sindresorhus / normalize-url

Normalize a URL
MIT License
840 stars 122 forks source link

What should happen with trailing slash plus query? #42

Closed jotto closed 6 years ago

jotto commented 7 years ago

Right now it looks like a normalization bug, unless these are in fact 2 different URLs:

> normalizeUrl('/index/?a=b')
'/index/?a=b'
> normalizeUrl('/index?a=b')
'/index?a=b'
sindresorhus commented 7 years ago

Not sure. Removing trailing slash with a query string is not always a safe change.

For example, https://sindresorhus.com/feedback/?foo works, but https://sindresorhus.com/feedback?foo does not.

SamVerschueren commented 7 years ago

They aren't the same thing. If I'm not mistaken, some REST APIs tend to use /resource/ to get a list of the resources and /resource to get one resource.

jotto commented 7 years ago

This might be a case-by-case thing. Based on @SamVerschueren's observation, the existing functionality might be wrong too:

> normalizeUrl('example.com/index/')
'http://example.com/index'

If the server is...

stevenvachon commented 7 years ago

Removing a trailing slash regardless of a query is not always safe, as pointed out by @jotto. This library is already opinionated in regards to what is safe, though, so you may not always want the default settings.