fix: respect backslash-escaped quotes when splitting quoted parameters - #107
Open
rajanpanth wants to merge 1 commit into
Open
fix: respect backslash-escaped quotes when splitting quoted parameters#107rajanpanth wants to merge 1 commit into
rajanpanth wants to merge 1 commit into
Conversation
quoteCount() counted every literal DQUOTE to decide whether a comma or semicolon fell inside an open quoted-string, with no awareness of a preceding backslash. Per RFC 7230 section 3.2.6, quoted-pair allows an escaped DQUOTE inside a quoted-string without closing it, so a value like p="\"" threw off the parity count and caused the next, unrelated media type in the Accept header to be silently merged into the previous one and dropped from the result.
Author
|
Friendly follow-up on this PR 👋 When you have a moment, could you please take a look? I’m happy to update anything if needed. Thanks! |
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.
Summary
quoteCount()counts every literal DQUOTE to decide whether a comma/semicolon falls inside an open quoted-string, with no awareness of a preceding backslash. Per RFC 7230 §3.2.6,quoted-pairallows an escaped DQUOTE inside a quoted-string without closing it — so a parameter value containing\"throws off the parity count, and the parser thinks it's still inside a quoted string when the next media type begins.A perfectly valid Accept header that explicitly lists
application/jsongets it silently dropped, which could causeaccepts/Express'sres.format()to return a wrong-content-type response or a spurious 406.Changes
lib/mediaType.js:quoteCount()now walks the string char-by-char, skipping the character after any backslash instead of naively counting every DQUOTE.test/mediaType.js: two new cases alongside the existing unescaped-comma-in-quotes test (issue Fails to parse quoted parameters #36) — an escaped DQUOTE, and an escaped backslash immediately before a real closing DQUOTE (to confirm double-backslash doesn't false-positive).Testing
eslint .clean.