summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmanuele Torre <torreemanuele6@gmail.com>2023-12-13 20:14:31 +0100
committerGitHub <noreply@github.com>2023-12-13 20:14:31 +0100
commitc5fd64ba975ee35df17bb0c335efb00bffce4d91 (patch)
treeafb0dda1f014d876319007e5d1e8603e0c77464f
parentdcf9a8e580e3607e70737fad8bc0987d30be871b (diff)
jv_parse: let decNumberFromString/strtod parse complex nans as a NaN
Before this patch (when using decNumber), "Nan123" was parsed as a NaN, only if the first n was uppercase.
-rw-r--r--src/jv_parse.c2
-rw-r--r--tests/jq.test5
2 files changed, 6 insertions, 1 deletions
diff --git a/src/jv_parse.c b/src/jv_parse.c
index 110483a4..9755b8ac 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 4c8416dc..7036df2c 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