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

Backslashes are wrongly escaped in grammar_codegen #915

Open
racko opened this issue Jan 17, 2024 · 0 comments · May be fixed by #916
Open

Backslashes are wrongly escaped in grammar_codegen #915

racko opened this issue Jan 17, 2024 · 0 comments · May be fixed by #916

Comments

@racko
Copy link

racko commented Jan 17, 2024

When I change fuzztest/grammars/JSON.g4 to support some escape sequences

STRING : '"' (CHARACTER | '\\' ESCAPED )* '"' ;

ESCAPED : '"' | '\\' | '/' | 'b' | 'f' | 'n' | 'r' | 't' ;

then the grammar tests fail because the nlohmann/json library fails to parse the generated json:

$ bazel test //domain_tests:in_grammar_domain_test
...
Executing tests from //domain_tests:in_grammar_domain_test
-----------------------------------------------------------------------------
Running main() from gmock_main.cc
[==========] Running 6 tests from 2 test suites.
[----------] Global test environment set-up.
[----------] 5 tests from InJsonGrammar
[ RUN      ] InJsonGrammar.InitGeneratesDifferentValidJson
domain_tests/in_grammar_domain_test.cc:41: Failure
Value of: parsed_json.is_discarded()
  Actual: true
Expected: false
"{\"\\\\\"\":[80.0E3,false]}"
...

That's because backslashes are escaped when they shouldn't be. E.g. "\"" (quote, escaped quote, quote) becomes "\\"" (quote, escaped backslash, quote, quote), which is not correct json.

The linked PR fixes the issue.

@racko racko linked a pull request Jan 17, 2024 that will close this issue
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 a pull request may close this issue.

1 participant