diff --git a/src/jv_parse.c b/src/jv_parse.c index 110483a4af..9755b8ac47 100644 --- a/src/jv_parse.c +++ b/src/jv_parse.c @@ -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(); } } diff --git a/tests/jq.test b/tests/jq.test index 945ea04f1c..39e3c91191 100644 --- a/tests/jq.test +++ b/tests/jq.test @@ -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