Skip to content

[Repo Assist] fix: correct JSON block comment parser to handle * and / inside comments#1710

Merged
dsyme merged 2 commits intomainfrom
repo-assist/fix-json-comment-star-slash-8a437cb8a13728dd
Mar 24, 2026
Merged

[Repo Assist] fix: correct JSON block comment parser to handle * and / inside comments#1710
dsyme merged 2 commits intomainfrom
repo-assist/fix-json-comment-star-slash-8a437cb8a13728dd

Conversation

@github-actions
Copy link
Contributor

🤖 This is an automated pull request from Repo Assist, an AI assistant for this repository.

Summary

Fixes a bug in the JSON /* ... */ comment parser where a * or / character appearing inside the comment body caused premature loop termination and a subsequent ensure failure (exception).

Root Cause

The while-loop condition in JsonParser.skipComment used && instead of ||:

// Buggy: exits when s.[i] = '*' OR s.[i+1] = '/'
while i + 1 < s.Length && s.[i] <> '*' && s.[i + 1] <> '/' do
    i <- i + 1

By De Morgan's law, NOT A AND NOT B is equivalent to NOT (A OR B), meaning the loop exited the moment either character matched — not when both */ appeared in sequence. The fix is:

// Correct: exits only when s.[i] = '*' AND s.[i+1] = '/'
while i + 1 < s.Length && (s.[i] <> '*' || s.[i + 1] <> '/') do
    i <- i + 1

Failing Examples (before fix)

JsonValue.Parse """{ /* path/to/file */ "x": 1 }"""  // lone '/' triggered early exit
JsonValue.Parse """{ /* a * b */        "x": 1 }"""  // lone '*' triggered early exit

Both threw System.Exception: Invalid JSON starting at character ... before this fix.

Changes

File Change
src/FSharp.Data.Json.Core/JsonValue.fs && → `
tests/FSharp.Data.Core.Tests/JsonValue.fs 3 regression tests for the two failure patterns
RELEASE_NOTES.md Added 8.1.3 entry

Test Status

  • ✅ Build: succeeded (0 errors)
  • ✅ All core tests: 2896 passed, 2 skipped (pre-existing network sandbox skips)
  • ✅ New regression tests: 3 / 3 pass

Generated by Repo Assist ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@d1d884596e62351dd652ae78465885dd32f0dd7d

The while-loop condition used '&&' (De Morgan AND) which caused the
parser to exit too early whenever a bare '*' or '/' appeared inside
a /* ... */ comment body.  For example:

  /* path/to/file */   — the lone '/' stopped the scan
  /* a * b */          — the bare '*' stopped the scan

The correct guard is '||': keep scanning until we see BOTH '*' AND '/'
in sequence.

Adds three regression tests covering the previously-failing patterns.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dsyme dsyme marked this pull request as ready for review March 24, 2026 00:11
@dsyme dsyme merged commit e368c45 into main Mar 24, 2026
2 checks passed
@dsyme dsyme deleted the repo-assist/fix-json-comment-star-slash-8a437cb8a13728dd branch March 24, 2026 00:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant