fix(conf): treat numbers with a suffix followed by more characters as strings - #8263
fix(conf): treat numbers with a suffix followed by more characters as strings#8263koriyoshi2041 wants to merge 2 commits into
Conversation
lexConvenientNumber emitted an itemInteger whenever a digit followed a
size suffix (k, m, g, t, p, e and their uppercase variants). That made
values such as "0K1abc" or "5e7bcd" lex as the partial integer "0K" /
"5e7" with the remaining characters left dangling, so the parser then
errored with messages like:
Expected a top-level value to end with a new line, comment or EOF,
but got '1' instead.
A digit (or any other non-terminator) after a suffix means the token
is not a convenient number, so it should be lexed as a string instead.
This commonly bit unquoted passwords that happened to start with a
number and a suffix character.
Only emit itemInteger on a real value terminator (newline, EOF, map
end, value/array terminators or whitespace); otherwise fall through to
the string state.
Fixes nats-io#5186
Fixes nats-io#5189
Fixes nats-io#6891
Signed-off-by: kigland <shuaizhicheng336@gmail.com>
|
Claude finished @neilalexander's task in 3m 52s —— View job Code Review
SummaryThe fix is correct and minimal. The root cause was a single misplaced clause in Fix correctness —
|
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Signed-off-by: kigland <shuaizhicheng336@gmail.com>
|
Added two small regression checks for the remaining contexts: a negative suffixed token ( |
|
CI triage: the only red check I see is That looks unrelated to this conf lexer change; this PR only touches the parser path and |
The config lexer mis-parses unquoted values that start with a number, then a size/exponent suffix, then more characters.
lexConvenientNumberemitted an integer token as soon as it saw a digit after a suffix (k, m, g, t, p, e and their uppercase forms). So0K1abclexed as the integer0Kand5e7bcdas5e7, leaving the trailing characters behind. The parser then failed with errors like:This most often shows up with unquoted passwords that happen to begin with a number and one of those suffix letters (e.g.
password: 4e2abc).A digit, or any other non-terminator, after the suffix means the token isn't a convenient number, so it should be lexed as a string. The fix drops the
unicode.IsDigit(r)clause so an integer is only emitted on an actual value terminator (newline, EOF, map end, value/array terminator, whitespace); anything else falls through to the existing string state. This matches how1Ghzis already handled.Added lexer-level cases to
TestConvenientIntegerValuesand a parser-levelTestUnquotedStringStartingWithNumberAndSuffixcovering0K1abc,8m4dwr,5e7bcd-abc10and4e2abc, both at top level and inside an authorization block.Fixes #5186
Fixes #5189
Fixes #6891