querystring: validate surrogate pairs in encodeStr#62834
Open
deepview-autofix wants to merge 1 commit intonodejs:mainfrom
Open
querystring: validate surrogate pairs in encodeStr#62834deepview-autofix wants to merge 1 commit intonodejs:mainfrom
deepview-autofix wants to merge 1 commit intonodejs:mainfrom
Conversation
The surrogate pair path in `encodeStr` only checked that a second code unit existed; it did not verify that the leading unit was a high surrogate (0xD800-0xDBFF) or that the trailing unit was a low surrogate (0xDC00-0xDFFF). A lone high surrogate followed by a non-surrogate (or a lone low surrogate) was silently combined and emitted as a syntactically valid four-byte UTF-8 sequence representing an entirely different code point, producing malformed output that does not roundtrip through `querystring.parse`. Match `encodeURIComponent` semantics by throwing `ERR_INVALID_URI` when either half of the pair is not a valid surrogate. Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: DeepView Autofix <276251120+deepview-autofix@users.noreply.github.com> Co-Authored-By: Nikita Skovoroda <chalkerx@gmail.com> Signed-off-by: Nikita Skovoroda <chalkerx@gmail.com>
ChALkeR
reviewed
Apr 19, 2026
ChALkeR
reviewed
Apr 19, 2026
Comment on lines
-13
to
-14
| assert.strictEqual(qs.escape(`${String.fromCharCode(0xD800 + 1)}test`), | ||
| '%F0%90%91%B4est'); |
Member
There was a problem hiding this comment.
Note that this assertion is changed to throw, how encodeURIComponent behaves.
Member
There was a problem hiding this comment.
It was introduced in #12163 and was just increasing coverage / documenting behavior, not by design likely.
anonrig
approved these changes
Apr 19, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #62834 +/- ##
=======================================
Coverage 89.62% 89.63%
=======================================
Files 706 706
Lines 219136 219138 +2
Branches 41987 41991 +4
=======================================
+ Hits 196404 196421 +17
+ Misses 14611 14608 -3
+ Partials 8121 8109 -12
🚀 New features to boost your workflow:
|
Collaborator
Member
|
cc @nodejs/tsc as a safety measure While I think this is more of a fix than a semver-major, others might have different opinion/reasons Reasons for this being a fix:
Reasons for this being a major:
|
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.
The surrogate pair path in
encodeStronly checked that a second code unit existed; it did not verify that the leading unit was a high surrogate (0xD800-0xDBFF) or that the trailing unit was a low surrogate (0xDC00-0xDFFF). A lone high surrogate followed by a non-surrogate (or a lone low surrogate) was silently combined and emitted as a syntactically valid four-byte UTF-8 sequence representing an entirely different code point, producing malformed output that does not roundtrip throughquerystring.parse.Match
encodeURIComponentsemantics by throwingERR_INVALID_URIwhen either half of the pair is not a valid surrogate.Fixes: #62814