What should happen with trailing slash plus query?
Closed this issue · 4 comments
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'
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.
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.
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...
- a static file store
/dir-or-file/
is the same as/dir-or-file
and can't co-exist (and the trailing slash normalization seems correct)
- dynamic
/dir-or-file/
could be different than/dir-or-file
and you can't normalize a trailing slash (because you don't know if it's different or not)
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.