Skip to content

Commit

Permalink
jv_parse: let decNumberFromString/strtod parse complex nans as a NaN
Browse files Browse the repository at this point in the history
Before this patch (when using decNumber), "Nan123" was parsed as a NaN,
only if the first n was uppercase.
  • Loading branch information
emanuele6 committed Dec 13, 2023
1 parent 19453a6 commit 7c5fa6d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/jv_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ static pfunc check_literal(struct jv_parser* p) {
case 'f': pattern = "false"; plen = 5; v = jv_false(); break;
case 'n':
// if it starts with 'n', it could be a literal "nan"
if (p->tokenpos != 3) {
if (p->tokenbuf[1] == 'u') {
pattern = "null"; plen = 4; v = jv_null();
}
}
Expand Down
5 changes: 5 additions & 0 deletions tests/jq.test
Original file line number Diff line number Diff line change
Expand Up @@ -1938,6 +1938,11 @@ tojson | fromjson
{"a":nan}
{"a":null}

# also "nan with payload" #2985
fromjson | isnan
"nan1234"
true


# calling input/0, or debug/0 in a test doesn't crash jq

Expand Down

0 comments on commit 7c5fa6d

Please # to comment.