Skip to content

fix: keep escaped quotes intact when stripping JSON comments - #2168

Open
dingzhencoding wants to merge 1 commit into
FoundationAgents:mainfrom
dingzhencoding:fix/2165-repair-json-escape-aware-comments
Open

dingzhencoding wants to merge 1 commit into
FoundationAgents:mainfrom
dingzhencoding:fix/2165-repair-json-escape-aware-comments

Conversation

@dingzhencoding

Copy link
Copy Markdown

Features

  • Fix repair_json_format truncates valid JSON strings containing escaped quotes and URLs #2165: repair_json_format no longer truncates valid JSON strings that contain escaped quotes or // / # (e.g. URLs).
  • Make the quoted-string branch of the comment-stripping regex escape-aware (\. or non-quote/non-backslash), so \" does not end the string early.
  • Real comments outside strings are still removed.
  • Add regression tests for escaped quotes, URLs with ///#, and comment stripping.

Influence

  • LLM JSON repair no longer corrupts string values like say \"https://example.com\".
  • Existing comment-removal and bracket-repair behavior is unchanged.

Result

  • Isolated verification of repair_json_format (stdlib-equivalent pattern against the same cases):
    • old pattern: JSONDecodeError / truncated {"text": "say \"https:
    • new pattern: full round-trip preserved
    • real # / // comments outside strings still stripped
    • # / // inside strings preserved
    • bracket repair ({ xxx }] -> { xxx }) unchanged
  • Full MetaGPT suite not run locally (Windows env missing optional deps); CI should cover tests/metagpt/utils/test_repair_llm_raw_output.py.

Other
Closes #2165

repair_json_format treated a backslash-escaped quote as the end of a
string, so // or # inside a valid JSON string (e.g. a URL) was mistaken
for a comment and the rest of the line was deleted.

Make the quoted-string branch of the comment regex escape-aware and add
regression tests for escaped quotes, URLs, and real comments outside
strings.

Fixes FoundationAgents#2165

This branch had an error being deployed

1 failed deployment
unittest — c1dda979 Deployed Sep 29, 2026 by dingzhencoding via build (3.9) #1741
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.

repair_json_format truncates valid JSON strings containing escaped quotes and URLs

1 participant