Skip to content

Don't escape backslashes in grammar_codegen - #916

Open
racko wants to merge 1 commit into
google:mainfrom
racko:fix_escape
Open

racko wants to merge 1 commit into
google:mainfrom
racko:fix_escape

Conversation

@racko

@racko racko commented Jan 17, 2024

Copy link
Copy Markdown

Fixes #915

inline constexpr absl::string_view kStrLiteral19 = "[";
inline constexpr absl::string_view kStrLiteral4 = "\"";
inline constexpr absl::string_view kStrLiteral13 = "]";
inline constexpr absl::string_view kStrLiteral5 = "\\";

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Without the fix in antlr_frontend.cc, this (string of length one) "\\" would be (a string of length two) "\\\\".

Comment thread fuzztest/grammars/JSON.g4
// With some simplifications:
// - Restricted character set (e.g., no unicode chars).
// - No escape sequences (e.g., \n, \t, \uff01, etc.)
// - No unicode escape sequences (e.g., \uff01)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

After at first adding the unicode escape sequences, I had to remove them again because nlohmann/json actually validates that the generated codepoints are "proper":
https://github.com/nlohmann/json/blob/a259ecc51e1951e12f757ce17db958e9881e9c6c/include/nlohmann/detail/input/lexer.hpp#L359-L381

This branch has not been deployed

No deployments
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.

Backslashes are wrongly escaped in grammar_codegen

1 participant