Repository navigation
fix(json_utils): reject prose pseudo-JSON in single quotes/backticks - #82
Merged
Merged
Conversation
Follow-up to the string-aware brace scan: that change only skipped
double-quoted prose, so brace-shaped text in single quotes, backticks, or
bare prose (e.g. `{op: delete}`, '{x: 1}') still reached json_repair and was
fabricated into a bogus dict — strictly worse than None, since extract_json
feeds the optimizer's skill edits.
Add a _looks_json_like() guard before repair: a genuine JSON object's first
non-space char after `{` is `"` (a key) or `}` (empty). Prose pseudo-objects
start with a bare word and are rejected, while legitimate repair targets
(trailing commas, unescaped quotes inside string values) all begin with `"`
and pass — including objects whose string VALUES contain single quotes or
backticks, which must not be rejected.
Found by an independent GPT-5.5 re-review of the merged #79 code. Adds
regression tests for single-quoted / backticked / bare prose (-> None) and
for legitimate objects with quote/backtick string values (still repaired).
Tests: 30 pass (+3 skip) without json_repair, 33 pass with it, both clean
under -W error::RuntimeWarning.
Co-Authored-By: Claude <[email protected]>
Contributor
|
Yifan Yang (@Yif-Yang) please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to the string-aware brace scan merged in #79. That scan only skipped double-quoted prose, so brace-shaped text in single quotes, backticks, or bare prose (e.g.
`{op: delete}`,'{x: 1}') still reachedjson_repairand got fabricated into a bogus dict — strictly worse thanNone, sinceextract_jsonfeeds the optimizer's skill edits.Adds a
_looks_json_like()guard before repair: a genuine JSON object's first non-space char after{is"(a key) or}(empty). Prose pseudo-objects start with a bare word and are rejected; legitimate repair targets (trailing commas, unescaped quotes inside string values) all begin with"and pass — including objects whose string values contain single quotes or backticks.Found by an independent GPT-5.5 re-review of the merged #79 code.
Test plan
None(new regression tests).tests/test_json_utils.py: 30 pass +3 skip withoutjson_repair, 33 pass with it; both clean under-W error::RuntimeWarning.🤖 Generated with Claude Code