Skip to content

feat(parsing): single-quote JSON repair + raw bracket span (#28)#45

Merged
haasonsaas merged 1 commit intomainfrom
feat/roadmap-28-single-quote-roaddoc
Mar 14, 2026
Merged

feat(parsing): single-quote JSON repair + raw bracket span (#28)#45
haasonsaas merged 1 commit intomainfrom
feat/roadmap-28-single-quote-roaddoc

Conversation

@haasonsaas
Copy link
Collaborator

Summary

Test plan

  • cargo test parsing::llm_response (includes parse_json_with_single_quotes)
  • cargo clippy --all-targets

Made with Cursor

- repair_json_candidates: convert single-quoted keys/values to double-quoted
  via convert_single_quoted_json_to_double (issue #28)
- find_balanced_bracket_span: extract raw [..] or {..} when valid JSON not found,
  so repair can fix and parse
- ROADMAP: document #28 repairs; add #25 (dynamic context) to Shipped
- Test: parse_json_with_single_quotes

Made-with: Cursor
@haasonsaas haasonsaas merged commit e3b2b84 into main Mar 14, 2026
@cursor
Copy link

cursor bot commented Mar 14, 2026

PR Summary

Medium Risk
Moderate risk because it changes LLM response JSON extraction/repair heuristics, which could alter what comments are emitted or incorrectly “repair” malformed text. Scope is limited to parsing with added targeted tests for the new cases.

Overview
Improves structured LLM-output parsing by adding a non-JSON-validating fallback that extracts the first balanced [...]/{...} span when normal JSON discovery fails, so repair can still run.

Extends repair_json_candidates to convert single-quoted JSON-like output into valid JSON via convert_single_quoted_json_to_double, and adds a test covering this case. Updates the roadmap to mark these parsing fallbacks (and dynamic context) as shipped.

Written by Cursor Bugbot for commit 0fed671. This will update automatically on new commits. Configure here.

Comment on lines +455 to +457
} else {
out.push(c);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The convert_single_quoted_json_to_double function incorrectly handles backslash escape sequences in single-quoted strings, causing it to produce invalid JSON for inputs containing escapes like \n.
Severity: HIGH

Suggested Fix

In the inner loop of convert_single_quoted_json_to_double that processes single-quoted strings, ensure the escape_next flag is reset to false after processing the character that follows a backslash. This should be done in the else block and after handling an escaped single quote if the logic is to continue processing.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: src/parsing/llm_response.rs#L455-L457

Potential issue: The function `convert_single_quoted_json_to_double` incorrectly
processes backslash escape sequences within single-quoted strings. When a backslash is
encountered, an `escape_next` flag is set to true. However, this flag is not reset if
the following character is anything other than a single quote. This causes the flag to
persist across subsequent characters in the string. As a result, when the actual closing
single quote is found, it is incorrectly treated as an escaped character, leading to a
malformed output string that is not valid JSON (e.g., it may be missing a closing
double-quote). This will cause JSON parsing to fail for any LLM response containing
single-quoted strings with common escape sequences like `\n` or `\t`.

Did we get this right? 👍 / 👎 to inform future reviews.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is ON. A cloud agent has been kicked off to fix the reported issue.

out.push('"');
} else {
out.push(c);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inner loop never resets escape_next for non-quote chars

High Severity

In convert_single_quoted_json_to_double, the inner for loop processing single-quoted string contents sets escape_next = true when it encounters \, but only checks/resets escape_next inside the c == '\'' branch. For any non-quote character following a backslash (e.g. \n, \t, \\), escape_next remains true indefinitely. This causes the actual closing ' to be misidentified as an escaped quote, producing corrupted output or an unclosed string. The outer loop and find_balanced_json both correctly handle this by checking escape_next at the top of the loop — the inner loop needs the same pattern.

Fix in Cursor Fix in Web

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.

1 participant