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 = """