fix(install): make JSONC sanitizer string-aware (#553)#578
Open
dlwjdghkszkf-png wants to merge 1 commit into
Open
fix(install): make JSONC sanitizer string-aware (#553)#578dlwjdghkszkf-png wants to merge 1 commit into
dlwjdghkszkf-png wants to merge 1 commit into
Conversation
The config merge in install_platform_configs reduced JSONC to strict JSON
with two regexes that ignored string boundaries:
re.sub(r'//.*?$', '', raw, flags=re.MULTILINE)
re.sub(r',(\s*[}\]])', r'\1', stripped)
Both corrupt string *values*. The first truncates any "https://..." URL at
the "//"; the second deletes a comma inside "foo, bar" when the next
non-space char is "}" or "]". The damaged text then parses to silently
wrong data (or fails json.loads outright).
Replace both with _strip_jsonc(): a single character-walking pass that
tracks in-string state (honoring backslash escapes) and only removes "//"
and "/* */" comments and trailing commas in structural position. Content
inside string values is preserved verbatim. Drop the now-unused `import re`.
Add TestStripJsonc covering the tirth8205#553 repro, URL preservation, escaped
quotes, in-string comment markers, and real comment / trailing-comma
removal.
|
This is solid — the character-by-character walk with string state tracking is the right approach. I had opened #571 with a simpler version that only handled trailing commas, but this covers both comments and commas in one pass. Just closed mine in favor of this. The |
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.
Fixes #553.
Problem
install_platform_configsreduces an existing JSONC config to strict JSON before merging, using two regexes that don't track string boundaries:Both corrupt string values:
//stripper truncates a"https://..."URL at the//"foo, bar"when the next non-space char is}or]The damaged text then fails
json.loads, or — worse — parses to silently wrong data, corrupting the user's config on write-back.Fix
Replace both regexes with
_strip_jsonc(): a single character-walking pass that tracks in-string state (honoring\escapes) and only removes//+/* */comments and trailing commas in structural position. Content inside string values is preserved verbatim. The now-unusedimport reis dropped.Tests
New
TestStripJsonc(10 cases): the #553 repro (comma inside a string before}),https://URL preservation, escaped quotes, in-string comment markers ("x // y","p /* q */ r"), and real comment / trailing-comma removal.Validation:
pytest tests/test_skills.py→ 146 passed (10 new)mypy code_review_graph/skills.py→ cleanruff check code_review_graph/skills.py→ clean