johnste / finicky

A macOS app for customizing which browser to start
MIT License
3.74k stars 137 forks source link

URL fragment not handled properly when resolving short urls #184

Open thobe opened 3 years ago

thobe commented 3 years ago

Describe the bug When a shortened URL contains a fragment identifier (ending with #-something), Finicky encodes that # as %23, which results in making it part of the actual URL, rather than a fragment.

Your configuration Nothing relevant.

To Reproduce Steps to reproduce the behavior:

  1. Open the link https://bit.ly/3lsQ95c through Finicky (e.g. from the command line as open 'https://bit.ly/3lsQ95c')
  2. This should resolve to https://github.com/johnste/finicky#table-of-contents (which is what it does if you enter https://bit.ly/3lsQ95c directly in your web browsers address bar).
  3. But instead it resolves to https://github.com/johnste/finicky%23table-of-contents, causing a 404 from GitHub.
jtrott commented 2 years ago

I've worked around the issue for now with the following:

        {
            match: ({ url }) => url.host.endsWith("independentaustralia.net"),
            url: ({ url }) => {
                return {
                ...url,
                host: url.host,
                pathname: url.pathname.replace(/\%23.+/g, '')
                }
            }
        }
glasser commented 1 year ago

Note that the workaround assumes that the shortened URL only can contain non-encoded #.

sashkab commented 1 year ago

Wouldn't be it easier to use decodeURI(url) in return? (or something similar)?

glasser commented 1 year ago

I mean it would probably be better to fix the underlying bug...

Personally I'd be fine if Finicky merely resolved URL shorteners in order to decide which browser to use but then still gave the original short URL to the browser.

jtrott commented 1 year ago

That would be an excellent solution.

glasser commented 1 year ago

Alternatively, looks like perhaps taking the calls to addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) and adding # to the .urlQueryAllowed character set would work?