Skip to content

fix(jsonc): report unterminated strings as unexpected end of input - #7302

Open
tomas-zijdemans wants to merge 1 commit into
denoland:mainfrom
tomas-zijdemans:fix-jsonc-unterminated-string
Open

fix(jsonc): report unterminated strings as unexpected end of input#7302
tomas-zijdemans wants to merge 1 commit into
denoland:mainfrom
tomas-zijdemans:fix-jsonc-unterminated-string

Conversation

@tomas-zijdemans

Copy link
Copy Markdown
Contributor

An unterminated string now reports the truncation instead of blaming the token.

Before, parse('"abc') threw:

Cannot parse JSONC: unexpected token ""abc" in JSONC at position 0

Every other truncated input says Cannot parse JSONC: unexpected end of JSONC input. Unterminated strings were the exception, and {"a": "b had the same problem.

The tokenizer's string branch yields a String token whether or not it found the closing quote. The failure then surfaces downstream, when JSON.parse chokes on the token text, so it reads as a bad token rather than a file that stopped early. The fix tracks hasEndOfString and throws the end-of-input error, mirroring the hasEndOfComment check for unterminated block comments 50 lines above it.

Still a SyntaxError. Message only, no type change, no change to any input that parses.

7 lines in parse.ts, plus 2 cases in the existing parse() throws error message test. #5799 aligned the other jsonc messages the same way.

deno fmt, deno lint, deno task lint:docs, and the jsonc suite (408 tests) all pass.

I used Claude Code to help investigate and write this change.

@github-actions github-actions Bot added the jsonc label Sep 3, 2026
@codecov

codecov Bot commented Sep 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.03%. Comparing base (ca58f94) to head (58789ba).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7302      +/-   ##
==========================================
- Coverage   95.03%   95.03%   -0.01%     
==========================================
  Files         617      618       +1     
  Lines       51637    51898     +261     
  Branches     9359     9410      +51     
==========================================
+ Hits        49075    49323     +248     
- Misses       2021     2030       +9     
- Partials      541      545       +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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