Skip to content

fix: QUOTED_STRING regex - #23

Closed
dkw-oss wants to merge 1 commit into
socketry:mainfrom
dkw-oss:minor-patch
Closed

dkw-oss wants to merge 1 commit into
socketry:mainfrom
dkw-oss:minor-patch

Conversation

@dkw-oss

@dkw-oss dkw-oss commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

bugfix: a minor improvement to a header parsing

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The updated QUOTED_STRING still permits escaped carriage returns (via \\.), so line breaks can still slip through in quoted values despite the new rejection intent/tests.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR updates the quoted-string parsing used by HTTP::Accept::MediaTypes to avoid QUOTED_STRING over-matching (particularly around escaped backslashes), and adds regression tests to validate correct Accept header parsing behavior.

Changes:

  • Replace the QUOTED_STRING regex used for parsing quoted parameter values.
  • Add a regression test for a quoted value ending in an escaped backslash.
  • Add tests asserting line breaks inside quoted values are rejected.
File summaries
File Description
test/http/media_types.rb Adds regression tests for quoted-string edge cases in Accept header parameter parsing.
lib/http/accept/quoted_string.rb Updates the QUOTED_STRING regex used by the Accept header parser.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

# According to https://tools.ietf.org/html/rfc7231#appendix-C
TOKEN = /[!#$%&'*+\-.^_`|~0-9A-Z]+/i
QUOTED_STRING = /"(?:.(?!(?<!\\)"))*.?"/
QUOTED_STRING = /"(?:[^"\\\r\n]|\\.)*"/
Comment thread test/http/media_types.rb
Comment on lines +54 to +57
[
"foo/bar;x=\"line\rbreak\"",
"foo/bar;x=\"line\nbreak\"",
].each do |text|
@ioquatix

ioquatix commented Sep 6, 2026

Copy link
Copy Markdown
Member

The proposed fix was released in v2.2.2 but it looks like we might need another refinement to the pattern?

@ioquatix ioquatix closed this Sep 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants