fix(url): ignore fragment identifiers in getPath() (#4627)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
* fix(url): ignore fragment identifiers in getPath() In Service Worker contexts, URLs may contain fragment identifiers (#) which should not be included in route matching. This change modifies getPath() to strip fragment identifiers from the path, consistent with how query strings are already handled. Fixes #4440 * fix: handle fragment before query in percent-encoded paths When a URL contains a fragment with query-like characters (e.g., #section?foo=bar), the previous logic would incorrectly include the fragment in the path because it checked for '?' first and only looked for '#' if '?' was not found. This fix uses Math.min() to find whichever delimiter ('?' or '#') comes first, correctly handling edge cases per RFC 3986 where '#' terminates the path regardless of subsequent '?' characters in the fragment. Added test case for this edge case. * test(url): add test for encoded hash (%23) in path with fragment Verify that percent-encoded hash (%23) is preserved while real fragment identifiers are correctly stripped. decodeURI preserves reserved characters per Web Standards. * perf(url): reduce === -1 evaluations in getPath Restructure ternary to avoid redundant separator === -1 check. For /path?x=1, reduces evaluations from 3 to 2. Co-authored-by: usualoma <usualoma@users.noreply.github.com> * test(url): add coverage for percent encoding without query or fragment Cover the undefined branch when both queryIndex and hashIndex are -1. ---------
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Trailers
- Co-authored-by: sanosuguru <sa.50.00.no.riku@gmail.com>
- Co-authored-by: usualoma <usualoma@users.noreply.github.com>
Diff stats
2 files+59 added−4 removed
- tests:+46 added−0 removed
- other:+13 added−4 removed