json-schema-org / json-schema-org/website

🐛 Bug: Custom JSON parser fails on escaped backslashes preceding quotes

Open
#2,013 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

🐛 Bug Status: Triage
Dominant language
HTML
Stars
169
Forks
484
Avg merge
2d 2h
Merged PRs (30d)
6

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 :-
Image
Buggy :-
Image
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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in lib/getPartsOfJson.ts and reproduce the issue from pages/understanding-json-schema/basics.md with the JSON block shown. Inspect how the parser finds string boundaries around escaped backslashes; done means the following key and the rest of the code block no longer receive string highlighting or path-detection errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.