Skip to content
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

use unicode-resilient approach to exclude sub delimiters #67

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

martinklepsch
Copy link

@martinklepsch martinklepsch commented Mar 13, 2024

Fixes troch/route-node#39
Fixes router5/router5#499

Hello!

I know this library is probably in kind of a "done" state but I noticed some issues with emojis in query params and decided to investigate. In the end it turned out the .replace method breaks apart unicode characters in a way that will later trip up encodeURIComponent.

Iterating over characters as done in this PR ensures that surrogate pairs are kept as-is and thus path building works as expected even when emojis are provided as part of path parameters.

Screenshot 2024-03-13 at 22 39 52
(source)

I also added some tests to demonstrate that this is working as intended.

Cheers

Comment on lines +33 to +34
if (subDelimiters.test(char)) {
return char // Return the character as is if it's a sub-delimiter
Copy link
Author

Choose a reason for hiding this comment

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

This could probably be optimized a bit more, perhaps checking for character codes instead of matching against a regex. But maybe JS engines are so smart these days that it doesn't matter. Did you ever benchmark path-parser?

@lorentzimys
Copy link

@troch is this fix is supposed to be merged? I've faced an issue described here router5/router5#499 and also waiting for this MR to be resolved🙏

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.

BUG: errors handling unicode emoji BUG: errors handling unicode emoji
2 participants