Skip to content

Escape control characters in natural UTF-8 JSON - #9451

Open
HocVoNgThai wants to merge 1 commit into
google:masterfrom
HocVoNgThai:fix/natural-utf8-control-characters
Open

HocVoNgThai wants to merge 1 commit into
google:masterfrom
HocVoNgThai:fix/natural-utf8-control-characters

Conversation

@HocVoNgThai

Copy link
Copy Markdown

When exporting JSON with --natural-utf8, flatc writes some control characters directly into string values instead of escaping them. The command succeeds, but the generated JSON is invalid and cannot be read by standard JSON parsers.

For example, this valid input:

{"text": "café\u0000menu"}

is exported with a raw NUL byte in place of \u0000, causing JSON parsing to fail.

This fix preserves \u0000 as an escape sequence while keeping café readable, producing valid JSON without losing the original string content.

The regression test covers all 32 control characters, checks that Unicode remains readable, and verifies that the generated JSON can be parsed again.

@google-cla

google-cla Bot commented Oct 30, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@github-actions github-actions Bot added the c++ label Oct 30, 2026

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant