You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
importTrouterfrom'trouter'constrouter=newTrouter()router.get('/kitten',_=>{console.log('Meow from plain text route path!')}).get('/😸',_=>{console.log('Meow from emoji route path!')})// Find a route definitionconstkittenText=router.find('GET','/kitten')constkittenEmoji=router.find('GET','/😸')// Both handlers execute as expected.kittenText.handlers[0]()kittenEmoji.handlers[0]()
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 sveltejs/kit#2171).
So here’s the above example, with the workaround implemented:
importpathfrom'node:path'importpolkafrom'polka'constencodeFilePath=filePath=>filePath.split(path.sep).map(value=>encodeURIComponent(value)).join(path.sep)polka().get(encodeFilePath('/kitten'),(_request,response)=>response.end('Meow!')).get(encodeFilePath('/😸'),(_request,response)=>response.end('Meow!')).listen(3000,_=>{console.log('Visit http://localhost:3000/kitten (works)')console.log('and http://localhost:3000/😸 (now also works).')})
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.
The text was updated successfully, but these errors were encountered:
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.
aral
changed the title
Router fails when emoji is included in path
Router fails when emoji/unicode is included in path
Dec 15, 2022
aral
changed the title
Router fails when emoji/unicode is included in path
Routing fails when unicode (e.g., emoji) is included in request path
Dec 15, 2022
aral
changed the title
Routing fails when unicode (e.g., emoji) is included in request path
Polka does not support unicode in URIs.
Dec 15, 2022
aral
changed the title
Polka does not support unicode in URIs.
Polka does not support unicode in routing patterns.
Dec 15, 2022
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 sveltejs/kit#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.
The text was updated successfully, but these errors were encountered: