mirror of
https://github.com/nlohmann/json.git
synced 2026-08-29 12:27:32 +00:00
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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MXDi7NTMKAmoArUZSKMc4T Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user