Skip to content

Print descriptions as quoted strings when a block string cannot hold them - #156

Open
swalkinshaw wants to merge 1 commit into
mainfrom
printer-block-string-fallback
Open

swalkinshaw wants to merge 1 commit into
mainfrom
printer-block-string-fallback

Conversation

@swalkinshaw

@swalkinshaw swalkinshaw commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

BlockStringValuePrinter writes every description as a block string, so some descriptions change after a print and parse. Block string parsing removes common indentation and leading and trailing blank lines, and treats \r as a line terminator (spec).

Description Value after print and parse, before this PR
"\nfoo" "foo"
"foo\n" "foo"
" foo" "foo"
"a\r\nb" "a\nb"

The printer now writes these values as quoted strings. The check is based on graphql-js isPrintableAsBlockString, adapted to the multi-line format that Bluejay prints. All other descriptions print as before, so no snapshots change.

Quoted strings now also escape control characters as \uXXXX, like graphql-js. Bluejay parses raw control characters, but parsers that follow the June 2018 spec reject them.

…them

Block string parsing removes common indentation and leading and trailing
blank lines, and treats \r as a line terminator. So descriptions such as
"\nfoo", "foo\n" and "  foo" changed after a print and parse. Fall back
to a quoted string for these values, and escape control characters in
quoted strings.

Found by fuzzing with apollo-smith.
@swalkinshaw
swalkinshaw marked this pull request as ready for review October 22, 2026 20:22

@gmac gmac left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice. Idempotence is good.

@swalkinshaw
swalkinshaw requested a review from adampetro October 28, 2026 15:30
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