Repository navigation
Fix encoding of a "%" next to a valid sequence or at the end - #40
Merged
blakeembrey merged 2 commits intoNov 11, 2026
Merged
Conversation
An invalid "%" consumed the following character, so "%%41" became "%25%2541" (the valid %41 was encoded too) and a truncated "%A" at the end was left as-is. Use a lookahead instead.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #40 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 1 1
Lines 5 5
Branches 1 1
=========================================
Hits 5 5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
UlisesGascon
approved these changes
Nov 11, 2026
Merged
Member
|
Made some additional changes to handle large inputs properly but otherwise LGTM. |
This was referenced Nov 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
An invalid
%is matched together with the character after it (%[0-9A-Fa-f]?[^0-9A-Fa-f]). That has two effects:%of a valid sequence, that sequence is encoded too:Both differ from what the README promises (
%is only encoded when it is not part of a valid sequence). 2.x has the same behavior, so this affectsres.location()/res.redirect()in Express too.The fix replaces the consuming match with a lookahead,
%(?![0-9A-Fa-f]{2}), so only the%itself is encoded and the following characters are handled on their own.Testing: two new specs fail on master and pass with the fix;
npm test(prettier, tsc, vitest, 100% coverage) passes. I also ran 300k random strings built from%, hex digits, other ASCII, non-ASCII and lone surrogates: on master 23,403 outputs still contained a%not followed by two hex digits, with the fix none did, and every output contains only URL code points.