Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(parser,compiler): fix string serialization bugs found by fuzzing #774

Merged
merged 9 commits into from
Dec 7, 2023

Conversation

goto-bus-stop
Copy link
Member

Two minor fixes:

  • Leading whitespace on a single-line string can not be serialized as a block string
  • \\""" in a block string should be lexed as \ followed by \""", previously the first backslash escaped the second backslash and caused the """ to be interpreted as the end of the string.

goto-bus-stop and others added 8 commits December 7, 2023 13:12
When parsing a block string, the first line does not affect the common
indent, as it would normally have no indent at all. But when
serializing a string to a block string, the first line *is* important,
namely for a single-line string that starts with whitespace.

Assume a text like this:
```
    Starts with "spaces"
```

If we skip the first line, the common indent is detected as 0,
producing this output:
```graphql
"""
    Starts with "spaces"
"""
```

Now when reparsing, the common indent is detected as 4, and you get
back:
```
Starts with "spaces"
```
which is wrong.
Backslash is not special in block strings except in the exact sequence
`\"""`. So if you write `\\"""`, that sequence should still be treated
as the escape sequence for `"""`. This patch fixes that.

Previously, we would return to the BlockStringLiteral state on the
second `\`, and interpret the `"""` as the end of the string.
Copy link
Member

@lrlna lrlna left a comment

Choose a reason for hiding this comment

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

hell ya!

@goto-bus-stop goto-bus-stop merged commit 580d77b into main Dec 7, 2023
11 checks passed
@goto-bus-stop goto-bus-stop deleted the fuzz-strings branch December 7, 2023 13:54
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.

2 participants