Skip to content

Fix decoding entire pathname edge cases #192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

ventaur
Copy link
Contributor

@ventaur ventaur commented May 27, 2025

Fixes #191

One caveat with this change is that all invalid/reserved URI characters will now be encoded. This is necessary to prevent something like \ from appearing and then v8 flipping that to a /. This URL is an example of how things go wrong with %5C being decoded to \, then getting flipped to / by the URL class. This is a valid URL that you can visit in your browser to see the image.

https://tourpic-vector.maps.komoot.net/r/big/u%60t%5Be_pC~EzKnI%60p@h@nf@xFzJeB~EdQdXbH%60e@pHvOsAxp@lO%60VnA%7CVvyAhnAbYff@~P~ItT%5CjNjm@%7CQtU/?width=768&height=576&crop=true

However, if you run it through normalize-url, it will no longer map to the same resource on Komoot. Instead, you end up with this URL.

https://tourpic-vector.maps.komoot.net/r/big/u%60t[e_pC~EzKnI%60p@h@nf@xFzJeB~EdQdXbH%60e@pHvOsAxp@lO%60VnA%7CVvyAhnAbYff@~P~ItT/jNjm@%7CQtU/?width=768&height=576&crop=true

@ventaur
Copy link
Contributor Author

ventaur commented May 27, 2025

It looks like a rate limit was hit with Codecov for the Node.js 16 checks.

Also, I don't see the option to "Allow edits from maintainers”. Maybe the checks have to pass first?

test.js Outdated
Comment on lines 43 to 45
t.is(normalizeUrl('https://foo.com/some%5Bthing%5Celse/that-is%40great@coding'), 'https://foo.com/some[thing%5Celse/that-is%40great@coding');
t.is(normalizeUrl('https://foo.com/something\\else/great'), 'https://foo.com/something/else/great');
t.is(normalizeUrl('https://foo.com/something%5Celse/great'), 'https://foo.com/something%5Celse/great');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be better to have this in a separate test with a clear title, so it's easier to see what's being tested.

@sindresorhus sindresorhus merged commit 07c9a7b into sindresorhus:main Jun 9, 2025
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Decoding entire pathname leads to edge case issues
2 participants