aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordrh <>2023-04-01 23:29:59 +0000
committerdrh <>2023-04-01 23:29:59 +0000
commit8d1005a593b9d3f79b629c231180a48dce819371 (patch)
treec625dca629a9d7787e96e5671b2952561ab6ba6d
parent54b81e36ffff011aaf5173d7d9ba475819964bc8 (diff)
downloadsqlite-8d1005a593b9d3f79b629c231180a48dce819371.tar.gz
sqlite-8d1005a593b9d3f79b629c231180a48dce819371.zip
Allow special floating-point value names in JSON: "inf", "-inf", "infinity",
"-infinity", "nan", "qnan", and "snan". All are converted into valid JSON values: 9e999, -9e999, or null. Requires the SQLITE_ENABLE_JSON_NAN_INF compile-time option to operate. FossilOrigin-Name: fc8793e5acac7351749e360c6bace5d5a8b3de3aa600ae23e260557db650c461
-rw-r--r--manifest15
-rw-r--r--manifest.uuid2
-rw-r--r--src/json.c53
3 files changed, 63 insertions, 7 deletions
diff --git a/manifest b/manifest
index 402e7df22..b14a6fbe4 100644
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sharmless\scompiler\swarnings.
-D 2023-04-01T15:51:21.968
+C Allow\sspecial\sfloating-point\svalue\snames\sin\sJSON:\s\s"inf",\s"-inf",\s"infinity",\n"-infinity",\s"nan",\s"qnan",\sand\s"snan".\s\sAll\sare\sconverted\sinto\svalid\sJSON\nvalues:\s9e999,\s-9e999,\sor\snull.\s\sRequires\sthe\sSQLITE_ENABLE_JSON_NAN_INF\ncompile-time\soption\sto\soperate.
+D 2023-04-01T23:29:59.248
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -585,7 +585,7 @@ F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51
F src/hwtime.h b638809e083b601b618df877b2e89cb87c2a47a01f4def10be4c4ebb54664ac7
F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71
F src/insert.c a8de1db43335fc4946370a7a7e47d89975ad678ddb15078a150e993ba2fb37d4
-F src/json.c 9e3a6acf9e4fa8bb6c84a38538ed9c2f9ad09f106910ef0e9cc68e19c8dc4fc8
+F src/json.c 5ac77e419921a0e63dafe07b560e9ce5e9823055e814308559e4d54cc885a967
F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa
F src/loadext.c be5af440f3192c58681b5d43167dbca3ccbfce394d89faa22378a14264781136
F src/main.c 09bc5191f75dc48fc4dfddda143cb864c0c3dbc3297eb9a9c8e01fea58ff847d
@@ -2052,8 +2052,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P a1cb152e69c7c6cdd99300c91a8104716089de459d9d19e33ef38432aad70908
-R 1d46d8321fd0682be5d0a8790e197dc3
+P a4fb2864fe01cce9694242a0750623ca47fcecd68f74c4239d3eb5fbf978770a
+R d4fc5e6b6e165fd35d3ba84e2f999b35
+T *branch * json-nan-inf
+T *sym-json-nan-inf *
+T -sym-trunk *
U drh
-Z 9ba80d4da1e49f126926ac3e65e84ef8
+Z 2575536ea35edbedba9ae17b565e4eb0
# Remove this line to create a well-formed Fossil manifest.
diff --git a/manifest.uuid b/manifest.uuid
index 0a2dd04d5..ca3061fe8 100644
--- a/manifest.uuid
+++ b/manifest.uuid
@@ -1 +1 @@
-a4fb2864fe01cce9694242a0750623ca47fcecd68f74c4239d3eb5fbf978770a \ No newline at end of file
+fc8793e5acac7351749e360c6bace5d5a8b3de3aa600ae23e260557db650c461 \ No newline at end of file
diff --git a/src/json.c b/src/json.c
index 9783a3898..dbca6d2bb 100644
--- a/src/json.c
+++ b/src/json.c
@@ -757,6 +757,27 @@ static int jsonIs4Hex(const char *z){
return 1;
}
+#ifdef SQLITE_ENABLE_JSON_NAN_INF
+/*
+** Extra floating-point literals to allow in JSON.
+*/
+static const struct NanInfName {
+ char c1;
+ char c2;
+ char n;
+ char eType;
+ char nRepl;
+ char *zMatch;
+ char *zRepl;
+} aNanInfName[] = {
+ { 'i', 'I', 3, JSON_REAL, 7, "inf", "9.0e999" },
+ { 'i', 'I', 8, JSON_REAL, 7, "infinity", "9.0e999" },
+ { 'n', 'N', 3, JSON_NULL, 4, "NaN", "null" },
+ { 'q', 'Q', 4, JSON_NULL, 4, "QNaN", "null" },
+ { 's', 'S', 4, JSON_NULL, 4, "SNaN", "null" },
+};
+#endif /* SQLITE_ENABLE_JSON_NAN_INF */
+
/*
** Parse a single JSON value which begins at pParse->zJson[i]. Return the
** index of the first character past the end of the value parsed.
@@ -902,6 +923,24 @@ static int jsonParseValue(JsonParse *pParse, u32 i){
if( c<'0' || c>'9' ) return -1;
continue;
}
+#ifdef SQLITE_ENABLE_JSON_NAN_INF
+ /* Non-standard JSON: Allow "-Inf" (in any case)
+ ** to be understood as floating point literals. */
+ if( (c=='i' || c=='I')
+ && j==i+1
+ && z[i]=='-'
+ && sqlite3StrNICmp(&z[j], "inf",3)==0
+ ){
+ if( !sqlite3Isalnum(z[j+4]) ){
+ jsonParseAddNode(pParse, JSON_REAL, 8, "-9.0e999");
+ return i+4;
+ }else if( (sqlite3StrNICmp(&z[j],"infinity",8)==0 &&
+ !sqlite3Isalnum(z[j+5])) ){
+ jsonParseAddNode(pParse, JSON_REAL, 8, "-9.0e999");
+ return i+9;
+ }
+ }
+#endif
break;
}
if( z[j-1]<'0' ) return -1;
@@ -915,6 +954,20 @@ static int jsonParseValue(JsonParse *pParse, u32 i){
}else if( c==0 ){
return 0; /* End of file */
}else{
+#ifdef SQLITE_ENABLE_JSON_NAN_INF
+ int k, nn;
+ for(k=0; k<sizeof(aNanInfName)/sizeof(aNanInfName[0]); k++){
+ if( c!=aNanInfName[k].c1 && c!=aNanInfName[k].c2 ) continue;
+ nn = aNanInfName[k].n;
+ if( sqlite3StrNICmp(&z[i], aNanInfName[k].zMatch, nn)!=0 ){
+ continue;
+ }
+ if( sqlite3Isalnum(z[i+nn]) ) continue;
+ jsonParseAddNode(pParse, aNanInfName[k].eType,
+ aNanInfName[k].nRepl, aNanInfName[k].zRepl);
+ return i + nn;
+ }
+#endif
return -1; /* Syntax error */
}
}