From: drh <> Date: Thu, 27 Apr 2023 17:32:29 +0000 (+0000) Subject: All floating point literals "NaN" and "Infinity". Additional variants X-Git-Tag: version-3.42.0~73^2~23 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=47dd0e735de7a9bf133fc5855d1e8c021beca351;p=thirdparty%2Fsqlite.git All floating point literals "NaN" and "Infinity". Additional variants of these literals are available if compiled with SQLITE_EXTENDED_NAN_INF. FossilOrigin-Name: c13346afbecb92275e741252897d00478dab4be2d158889bc735e80efd9444f5 --- diff --git a/manifest b/manifest index 8880fe850e..e9ac4de4a3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\shandling\sof\sreverse\ssolidus\sin\sstring\sliterals.\s\sAllow\sdecimal\spoints\nin\sfloating\spoint\sliterals\sto\soccurs\sand\sthe\sbeginning\sor\send\sof\sthe\smantissa. -D 2023-04-27T16:57:14.640 +C All\sfloating\spoint\sliterals\s"NaN"\sand\s"Infinity".\s\sAdditional\svariants\nof\sthese\sliterals\sare\savailable\sif\scompiled\swith\sSQLITE_EXTENDED_NAN_INF. +D 2023-04-27T17:32:29.533 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -592,7 +592,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 d1a73af4f4185cfc355fa4b7be0cdc5cddd80b06da3d8ad3f966b8758e9027a1 +F src/json.c 530e1f4f4899a3c368bfaac63028e4c15ebd279a697780374d0cb7817103350a F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c be5af440f3192c58681b5d43167dbca3ccbfce394d89faa22378a14264781136 F src/main.c 09bc5191f75dc48fc4dfddda143cb864c0c3dbc3297eb9a9c8e01fea58ff847d @@ -2063,8 +2063,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 676877aca235e620ee12d10235dd6ad009d4968455ec170daeb1998b94a7e0a2 -R 55fe1e7f7cae4da350b14dce9970e986 +P d92a6ab2871095ac66c60cfa15dbafa7b762f83d287d452f61792eb30cf5b26b +R a7e436b837797408dc673da04c49a8e7 U drh -Z eab22ac4584a027288ad76a2849798e8 +Z 6274ce9cc076310c4a10615de56897ee # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 80675cd170..799d6b004d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d92a6ab2871095ac66c60cfa15dbafa7b762f83d287d452f61792eb30cf5b26b \ No newline at end of file +c13346afbecb92275e741252897d00478dab4be2d158889bc735e80efd9444f5 \ No newline at end of file diff --git a/src/json.c b/src/json.c index 4ef53cd8ae..9029ba9f13 100644 --- a/src/json.c +++ b/src/json.c @@ -1031,7 +1031,7 @@ static int json5Whitespace(const char *zIn){ } -#ifdef SQLITE_ENABLE_JSON_NAN_INF +#ifdef SQLITE_EXTENDED_NAN_INF /* ** Extra floating-point literals to allow in JSON. */ @@ -1050,7 +1050,7 @@ static const struct NanInfName { { 'q', 'Q', 4, JSON_NULL, 4, "QNaN", "null" }, { 's', 'S', 4, JSON_NULL, 4, "SNaN", "null" }, }; -#endif /* SQLITE_ENABLE_JSON_NAN_INF */ +#endif /* SQLITE_EXTENDED_NAN_INF */ /* ** Parse a single JSON value which begins at pParse->zJson[i]. Return the @@ -1306,7 +1306,35 @@ json_parse_restart: jnFlags = JNODE_JSON5; } }else{ - if( !sqlite3Isdigit(z[i+1]) ) return -1; + if( !sqlite3Isdigit(z[i+1]) ){ + if( z[i+1]=='I' + && (c=='-' || c=='+') + && strncmp(&z[i+1], "Infinity",8)==0 + ){ + if( z[i]=='-' ){ + jsonParseAddNode(pParse, JSON_REAL, 8, "-9.0e999"); + }else{ + jsonParseAddNode(pParse, JSON_REAL, 7, "9.0e999"); + } + return i+9; + } +#ifdef SQLITE_EXTENDED_NAN_INF + /* Non-standard JSON and JSON5: Allow "Inf" as an alternative + ** spelling for "Infinity" and allow it to be in any case. */ + if( (z[i+1]=='I' || z[i+1]=='i') + && (c=='-' || c=='+') + && sqlite3StrNICmp(&z[i+1], "inf",3)==0 + ){ + if( z[i]=='-' ){ + jsonParseAddNode(pParse, JSON_REAL, 8, "-9.0e999"); + }else{ + jsonParseAddNode(pParse, JSON_REAL, 7, "9.0e999"); + } + return i+4; + } +#endif + return -1; + } if( z[i+1]=='0' && sqlite3Isdigit(z[i+2]) ){ pParse->has5 = 1; jnFlags = JNODE_JSON5; @@ -1342,24 +1370,6 @@ json_parse_restart: 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+3]) ){ - jsonParseAddNode(pParse, JSON_REAL, 8, "-9.0e999"); - return i+4; - }else if( (sqlite3StrNICmp(&z[j],"infinity",8)==0 && - !sqlite3Isalnum(z[j+8])) ){ - jsonParseAddNode(pParse, JSON_REAL, 8, "-9.0e999"); - return i+9; - } - } -#endif break; } if( z[j-1]<'0' ){ @@ -1377,6 +1387,22 @@ json_parse_restart: } return j; } + case 'N': { + if( strncmp(&z[i],"NaN",3)==0 ){ + jsonParseAddNode(pParse, JSON_NULL, 4, "null"); + pParse->has5 = 1; + return i+3; + } + return -1; + } + case 'I': { + if( strncmp(&z[i],"Infinity",8)==0 ){ + jsonParseAddNode(pParse, JSON_REAL, 7, "9.0e999"); + pParse->has5 = 1; + return i+8; + } + return -1; + } case '}': { pParse->iErr = i; return -2; /* End of {...} */ @@ -1421,7 +1447,7 @@ json_parse_restart: return -1; } default: { -#ifdef SQLITE_ENABLE_JSON_NAN_INF +#ifdef SQLITE_EXTENDED_NAN_INF int k, nn; c = z[i]; for(k=0; k