From dac7d328e6a9c64292621ee03291d3cbb19c5d1e Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 23 Mar 2026 03:56:18 +0000 Subject: [PATCH 1/2] fix: correct JSON block comment parser to handle * and / inside comments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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> --- RELEASE_NOTES.md | 4 ++++ src/FSharp.Data.Json.Core/JsonValue.fs | 2 +- tests/FSharp.Data.Core.Tests/JsonValue.fs | 20 ++++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 121d622b9..30396dcd6 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,5 +1,9 @@ # Release Notes +## 8.1.3 - Mar 23 2026 + +- Fix JSON `/* ... */` comment parser: `*` or `/` characters inside the comment body no longer cause premature termination and parse failure + ## 8.1.2 - Mar 17 2026 - Fix `TextConversions.AsDateTime` and `TextConversions.AsDateTimeOffset` to return `None` (instead of throwing `ArgumentOutOfRangeException`) when a `/Date(...)/` value overflows the valid `DateTime`/`DateTimeOffset` range; use `InvariantCulture` explicitly when parsing the milliseconds value diff --git a/src/FSharp.Data.Json.Core/JsonValue.fs b/src/FSharp.Data.Json.Core/JsonValue.fs index e55625859..9f9c52b70 100644 --- a/src/FSharp.Data.Json.Core/JsonValue.fs +++ b/src/FSharp.Data.Json.Core/JsonValue.fs @@ -273,7 +273,7 @@ type private JsonParser(jsonText: string) = else if i < s.Length && s.[i] = '*' then i <- i + 1 - while i + 1 < s.Length && s.[i] <> '*' && s.[i + 1] <> '/' do + while i + 1 < s.Length && (s.[i] <> '*' || s.[i + 1] <> '/') do i <- i + 1 ensure (i + 1 < s.Length && s.[i] = '*' && s.[i + 1] = '/') diff --git a/tests/FSharp.Data.Core.Tests/JsonValue.fs b/tests/FSharp.Data.Core.Tests/JsonValue.fs index 846061255..af780688e 100644 --- a/tests/FSharp.Data.Core.Tests/JsonValue.fs +++ b/tests/FSharp.Data.Core.Tests/JsonValue.fs @@ -602,6 +602,26 @@ let ``JsonValue parsing with multi-line comments`` () = let result = JsonValue.Parse jsonWithComments result?data.AsString() |> should equal "valid" +[] +let ``JsonValue parsing with multi-line comment containing asterisk`` () = + // Bug: old code used '&&' so a '*' anywhere inside stopped scanning too early + let json = """{ /* a * b */ "x": 1 }""" + let result = JsonValue.Parse json + result?x.AsInteger() |> should equal 1 + +[] +let ``JsonValue parsing with multi-line comment containing slash`` () = + // Bug: old code used '&&' so a '/' anywhere inside stopped scanning too early + let json = """{ /* path/to/file */ "x": 2 }""" + let result = JsonValue.Parse json + result?x.AsInteger() |> should equal 2 + +[] +let ``JsonValue parsing with multi-line comment containing both asterisk and slash`` () = + let json = "{ /* a/b * c */ \"x\": 3 }" + let result = JsonValue.Parse json + result?x.AsInteger() |> should equal 3 + [] let ``JsonValue parsing with mixed whitespace and comments`` () = let jsonWithCommentsAndWhitespace = """ From 75a3bc2450722b2d404d0954a1438c05010dcf27 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 23 Mar 2026 04:02:57 +0000 Subject: [PATCH 2/2] ci: trigger checks