-
-
Notifications
You must be signed in to change notification settings - Fork 374
Description
Describe the bug
The custom JSON parser (implemented in lib/getPartsOfJson.ts) incorrectly identifies string boundaries when a string ends with an escaped backslash.
The parser uses the regex /(?<!\)"/g to find the closing quote of a string. This logic is flawed because it assumes any backslash immediately preceding a quote escapes that quote. However, in JSON, a backslash can itself be escaped.
For example, in the valid JSON string "slash: \", the first backslash escapes the second, and the following quote is the closing quote. Because the current regex sees a backslash before the quote, it fails to match it as the end of the string, causing the syntax highlighting and path detection to break for the entire remainder of the code block.
Steps To Reproduce
1.) Open any markdown file in the project (e.g., pages/understanding-json-schema/basics.md).
2.) Add a JSON code block that includes a trailing escaped backslash:
json
{
"bad_string": "backslash: \\",
"next_key": "this will be broken"
}
3.) Run yarn dev and navigate to that page.
4.) Observe: The syntax highlighting "leaks" out of the first string. The comma, the second key, and the rest of the block will all be colored as if they were still part of the first string.
Expected Behavior
The parser should correctly handle parity for escape sequences. A quote is only escaped if it is preceded by an odd number of backslashes.
Screenshots
Normal :-
Buggy :-
Device Information [optional]
- OS:
- Browser:
- version:Are you working on this issue?
Yes
Do you think this work might require an [Architectural Decision Record (ADR)]? (significant or noteworthy)
Yes