From ecd8003be1e204f27123220e43ef64b7e6d1a9ed Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Fri, 28 Aug 2026 14:50:29 +0000 Subject: [PATCH] Pin the number error position against a non-newline terminator The comment claimed the reported column is the one the offending token starts at. It is the column reached after the token's last character - which is the actual point of the unget() change: a number terminated by a newline now reports what the same number terminated by a space always did. Assert that equality directly, and add a multi-character token where the start and end columns differ, so the invariant cannot be read off a single-character example. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01MXDi7NTMKAmoArUZSKMc4T Signed-off-by: Niels Lohmann --- tests/src/unit-class_lexer.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/src/unit-class_lexer.cpp b/tests/src/unit-class_lexer.cpp index 70353b6f5..f138d33fa 100644 --- a/tests/src/unit-class_lexer.cpp +++ b/tests/src/unit-class_lexer.cpp @@ -411,11 +411,22 @@ TEST_CASE("lexer number fast path") CHECK(contiguous_what == streaming_error(doc)); } - // the column must be the one the offending token actually starts at, - // not the 0 that an unget() across the newline used to leave behind + // A number terminated by a newline must report the same position as the + // same number terminated by anything else: scan_number() reads the + // terminator and ungets it, so the reported column is the one reached + // after the number's last character - not the 0 that an unget() across + // the newline used to leave behind. + CHECK(contiguous_error("[01\n]") == contiguous_error("[01 ]")); CHECK(contiguous_error("[01\n]") == "[json.exception.parse_error.101] parse error at line 1, column 3: " "syntax error while parsing array - unexpected number literal; expected ']'"); + + // the same for a multi-character token, where the column of the last + // character (the '3' of "-2.5e3") differs from the column it starts at + CHECK(contiguous_error("null -2.5e3\nfalse") == contiguous_error("null -2.5e3 false")); + CHECK(contiguous_error("null -2.5e3\nfalse") == + "[json.exception.parse_error.101] parse error at line 1, column 11: " + "syntax error while parsing value - unexpected number literal; expected end of input"); } #endif }