Skip to content

fix(scan): keep reviews whose strings contain unmatched braces - #97

Open
JakeHuneau wants to merge 1 commit into
DataDog:mainfrom
JakeHuneau:extract-json-strings
Open

JakeHuneau wants to merge 1 commit into
DataDog:mainfrom
JakeHuneau:extract-json-strings

Conversation

@JakeHuneau

Copy link
Copy Markdown

Fixes #91.

extractJson paired the last } with a { by counting braces backward. Braces inside JSON strings count too, so a comment body with an unmatched brace (for example impl Foo {) moved the match onto an inner comment object, and a valid review failed to parse with "Unexpected non-whitespace character after JSON".

It now takes the earliest { whose slice up to the last } parses as JSON. Prose before the block still gets skipped, because a slice that starts in the prose doesn't parse. If no slice parses, it falls back to the old brace count, so malformed output still reaches the caller's parse error as before.

Tests:

  • Reviews whose comment bodies contain an unmatched { or }, both bare and fenced after prose with braces. These fail on main.
  • The fallback for output that isn't valid JSON.
  • npm test: 120 passing.

extractJson matched the last } with a { by counting braces, so a comment
body such as "impl Foo {" shifted the match onto an inner comment object
and the valid review failed to parse. Take the earliest { whose slice up
to the last } parses as JSON, and keep the brace count as the fallback
for output that is not valid JSON.

Fixes DataDog#91
@JakeHuneau
JakeHuneau requested a review from a team as a code owner October 29, 2026 11:39
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.

extractJson rejects valid review JSON containing unmatched braces in string values

1 participant