path-parser icon indicating copy to clipboard operation
path-parser copied to clipboard

use unicode-resilient approach to exclude sub delimiters

Open martinklepsch opened this issue 1 year ago • 1 comments

Fixes https://github.com/troch/route-node/issues/39 Fixes https://github.com/router5/router5/issues/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

martinklepsch avatar Mar 13 '24 20:03 martinklepsch

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

lorentzimys avatar May 07 '24 11:05 lorentzimys