Skip to content

fix(skills): string-aware trailing comma stripping for JSONC#571

Open
itxaiohanglover wants to merge 1 commit into
tirth8205:mainfrom
itxaiohanglover:fix/trailing-comma-string-aware
Open

fix(skills): string-aware trailing comma stripping for JSONC#571
itxaiohanglover wants to merge 1 commit into
tirth8205:mainfrom
itxaiohanglover:fix/trailing-comma-string-aware

Conversation

@itxaiohanglover

Copy link
Copy Markdown

Fixes #553

Problem

The regex r',(\s*[}\]])' in skills.py:351 strips trailing commas before } or ], but does not track JSON string boundaries. If a string value contains a comma followed by } or ] on the next line, the regex incorrectly removes the comma inside the string, corrupting the JSON.

Example breakage:

{
  "mcp": {
    "my-server": {
      "description": "foo, bar",
    }
  }
}

The comma in "foo, bar" gets removed → "foo bar" — silently corrupting user config.

What changed

Replaced the regex with _strip_trailing_commas_jsonc() — a minimal stateful parser that:

  1. Tracks in_string state (toggles on " outside of escape sequences)
  2. Only strips commas that are followed by } or ] outside of strings
  3. Handles escape sequences (\", \\) correctly

No new dependencies. No existing comments modified.

Validation

  • The existing json.loads(stripped) call on line 353 works unchanged
  • Strings containing ,} or ,] patterns are preserved
  • Trailing commas outside strings are still stripped correctly

The regex r',(\s*[}\]])' does not track JSON string boundaries.
If a string value contains a comma followed by } or ], the regex
incorrectly removes the comma inside the string, corrupting the JSON.

Replace with _strip_trailing_commas_jsonc() — a minimal stateful
parser that skips over quoted strings and only strips commas that
are followed by } or ] outside of strings.

Fixes tirth8205#553
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(install): trailing-comma regex breaks on commas inside string values

1 participant