Skip to content

fix: string-literal-aware normalization (prevents query corruption + hash collisions) - #18

Merged
mstuart merged 2 commits into
mainfrom
fix/string-literal-aware-normalize
Aug 26, 2026
Merged

fix: string-literal-aware normalization (prevents query corruption + hash collisions)#18
mstuart merged 2 commits into
mainfrom
fix/string-literal-aware-normalize

Conversation

@mstuart

@mstuart mstuart commented Aug 26, 2026

Copy link
Copy Markdown
Owner

Bug: normalizeQuery stripped # comments and collapsed whitespace across the entire query, including inside string literals.

  • { user(bio: "a # b") { name } } was truncated at the # to {user(bio:"a — everything after was lost, colliding with any other query truncating to the same prefix.
  • Whitespace inside strings was collapsed, so "a b" and "a b" (distinct values) hashed identically.

Fix: tokenize so string and """block""" literals are preserved verbatim, while comment-stripping and whitespace normalization apply only to surrounding source. Honors escaped quotes. All existing tests still pass; added 5 regression tests. ultracite check clean.

normalizeQuery stripped # comments and collapsed whitespace across the
whole query, including inside string literals. A query like
{ user(bio: "a # b") { name } } was truncated at the # to
{user(bio:"a — destroying everything after it and colliding with any
other query that truncates to the same prefix. Whitespace inside strings
was also collapsed, so distinct string values hashed identically.

Tokenize the query so string and block-string literals are preserved
verbatim while comment-stripping and whitespace normalization apply only
to the surrounding source. Handles escaped quotes and triple-quoted block
strings. Adds regression tests.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 19ed115584

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread index.js
Comment thread index.js Outdated
@mstuart
mstuart merged commit b843b72 into main Aug 26, 2026
7 checks passed
@mstuart
mstuart deleted the fix/string-literal-aware-normalize branch August 26, 2026 19:06

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8459fd209b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread index.js
) {
backslashes += 1;
}
if (end === -1 || backslashes % 2 === 0) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Treat every backslash-prefixed triple quote as escaped

When an escaped triple quote in a valid block string is immediately preceded by another backslash, GraphQL treats the first backslash as content and the second as the escape introducer, so the triple quote remains content. This parity check instead considers the two backslashes even and closes the block; a following # is then stripped as a comment, truncating the normalized operation and allowing distinct valid operations to collide. The newly added even/odd-backslash check is fresh evidence that the earlier escaped-triple-quote issue remains for this valid variant; a block-string triple quote should be considered escaped whenever its immediately preceding character is a backslash.

Useful? React with 👍 / 👎.

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.

1 participant