Skip to content

Accept an escaped single quote in JSON5 strings - #138

Merged
sheredom merged 1 commit into
sheredom:mainfrom
youdie006:json5-escaped-single-quote
Oct 12, 2026
Merged

sheredom merged 1 commit into
sheredom:mainfrom
youdie006:json5-escaped-single-quote

Conversation

@youdie006

Copy link
Copy Markdown
Contributor

JSON5 allows \' in strings (it is listed with the other single-character escapes in the spec), but neither escape switch has a case for it:

input flags main this PR npm json5
['a\'b'] allow_json5 / allow_single_quoted_strings error 4 (invalid_string_escape_sequence) ["a'b"] ["a'b"]
["c\'d"] same error 4 ["c'd"] ["c'd"]
["c\'d"] none error 4 error 4 (JSON rejects it)

This accepts \' in json_get_string_size when allow_single_quoted_strings is set (it is part of allow_json5) and writes a ' for it in json_parse_string. Without the flag it is still invalid_string_escape_sequence.

escaped_single_quote and escaped_single_quote_without_flag follow the other allow_single_quoted_strings tests; the first fails on main. Accepting it regardless of the flag fails the second, and writing the wrong character fails the first. The suite passes in gcc Debug and Release builds and in a Debug build with ASan and UBSan; I did not run clang, tcc or MSVC.

Written with AI assistance (Claude); I have reviewed the change.

JSON5 allows \' in both single- and double-quoted strings, but neither
escape switch had a case for it, so 'a\'b' failed with
invalid_string_escape_sequence under allow_json5. Accept it when single-
quoted strings are allowed, and keep rejecting it otherwise, as JSON does.
@sheredom
sheredom merged commit 079e223 into sheredom:main Oct 12, 2026
24 checks passed
@sheredom

Copy link
Copy Markdown
Owner

Good catch!

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