Open aral opened 1 year ago
Possibly the same issue as https://github.com/sveltejs/kit/issues/2166
(I’m seeing this on Polka 1.0.0-next.22.)
More observations:
If I add the route like this, it works:
.get('/%F0%9F%98%B8', (_request, response) => response.end('Meow!'))
Even if I use middleware to rewrite manually decode the URI component, it doesn’t work.
e.g.,
.use((request, _response, next) => {
console.log(request.path)
request.path = decodeURIComponent(request.path)
next()
})
You also cannot just encodeUriComponent()
the path you’re adding to the router as that will encode the slashes too and it still doesn’t work.
The problem
Polka does not support unicode in routing patterns.
(Routing fails when unicode – e.g., emoji or an ü, etc. – is included in the routing pattern.)
Basic reproduction
I’m assuming this is actually an issue in trouter, so going to try and reproduce there now but opening the issue here since it’s the main project that’s impacted.Nope, the bug is in Polka, not trouter:
You can replace the Kitten emoji with the letter
ü
and observe the same behaviour.Workaround
You must manually URI encode every component of the file path before adding your route to the router. Unless I’m mistaken, this is basically what SvelteKit does also (see https://github.com/sveltejs/kit/pull/2171).
So here’s the above example, with the workaround implemented:
Suggested solution
Based on the above workaround, Polka itself should apply the equivalent of the
encodeFilePath()
function internally and transparently when.get()
, etc., is called.Please let me know if you’d like a pull request for this; I’d be happy to prepare one.