diff options
author | drh <> | 2023-04-27 17:32:29 +0000 |
---|---|---|
committer | drh <> | 2023-04-27 17:32:29 +0000 |
commit | 47dd0e735de7a9bf133fc5855d1e8c021beca351 (patch) | |
tree | 117bd3ac4d9ced45eb5503b5f8915be23f4bea6c /src/json.c | |
parent | 8ded1642009400732782d4030d8d4359064531d0 (diff) | |
download | sqlite-47dd0e735de7a9bf133fc5855d1e8c021beca351.tar.gz sqlite-47dd0e735de7a9bf133fc5855d1e8c021beca351.zip |
All floating point literals "NaN" and "Infinity". Additional variants
of these literals are available if compiled with SQLITE_EXTENDED_NAN_INF.
FossilOrigin-Name: c13346afbecb92275e741252897d00478dab4be2d158889bc735e80efd9444f5
Diffstat (limited to 'src/json.c')
-rw-r--r-- | src/json.c | 70 |
1 files changed, 48 insertions, 22 deletions
diff --git a/src/json.c b/src/json.c index 4ef53cd8a..9029ba9f1 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<sizeof(aNanInfName)/sizeof(aNanInfName[0]); k++){ |