From: drh <> Date: Thu, 27 Apr 2023 18:28:10 +0000 (+0000) Subject: Add support for hexadecimal integer literals in JSON. X-Git-Tag: version-3.42.0~73^2~22 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=49d8e0ef976423671369bd86fbb67b69b2ae2864;p=thirdparty%2Fsqlite.git Add support for hexadecimal integer literals in JSON. FossilOrigin-Name: 85e00c9e68d0695592e8f72555ee133c096bfca5a860a8e21d1e0ef756705aaf --- diff --git a/manifest b/manifest index e9ac4de4a3..1118208d40 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -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 +C Add\ssupport\sfor\shexadecimal\sinteger\sliterals\sin\sJSON. +D 2023-04-27T18:28:10.882 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 530e1f4f4899a3c368bfaac63028e4c15ebd279a697780374d0cb7817103350a +F src/json.c e2830f713ac361dbdabcd9017acfb8e8e4a783ff5ca0f3925626edd8c7b11909 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c be5af440f3192c58681b5d43167dbca3ccbfce394d89faa22378a14264781136 F src/main.c 09bc5191f75dc48fc4dfddda143cb864c0c3dbc3297eb9a9c8e01fea58ff847d @@ -700,7 +700,7 @@ F src/trigger.c ad6ab9452715fa9a8075442e15196022275b414b9141b566af8cdb7a1605f2b0 F src/update.c 3f4fb5ad7c9b48d7911974d6579192bb3a6c27f46140b6cbb9139cc8a77b8691 F src/upsert.c 5303dc6c518fa7d4b280ec65170f465c7a70b7ac2b22491598f6d0b4875b3145 F src/utf.c ee39565f0843775cc2c81135751ddd93eceb91a673ea2c57f61c76f288b041a0 -F src/util.c b1d8d87c4c8c77e70f48c43f91444fd66d91532693573b70b837afd572010176 +F src/util.c d4bcb560471cd94e6e17d448311f8d5bf81a7e5276295a53501058ef1b95dd1a F src/vacuum.c 84ce7f01f8a7a08748e107a441db83bcec13970190ddcb0c9ff522adbc1c23fd F src/vdbe.c a6c52ba65e8ceb574fe0eda62af84e6c50c176ffc5f310c613425f7ab2b1484b F src/vdbe.h 637ae853b7d42ae3951034cc63ab7c8af837861f79504cdb5399552fcd89a884 @@ -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 d92a6ab2871095ac66c60cfa15dbafa7b762f83d287d452f61792eb30cf5b26b -R a7e436b837797408dc673da04c49a8e7 +P c13346afbecb92275e741252897d00478dab4be2d158889bc735e80efd9444f5 +R 6e312c065e46414b9040d6fd248d4cee U drh -Z 6274ce9cc076310c4a10615de56897ee +Z e7a3b5e2b439e9e4434717ea6eca66ea # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 799d6b004d..30c4114d5d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c13346afbecb92275e741252897d00478dab4be2d158889bc735e80efd9444f5 \ No newline at end of file +85e00c9e68d0695592e8f72555ee133c096bfca5a860a8e21d1e0ef756705aaf \ No newline at end of file diff --git a/src/json.c b/src/json.c index 9029ba9f13..10f6b9839d 100644 --- a/src/json.c +++ b/src/json.c @@ -372,6 +372,18 @@ static void jsonAppendNormalizedInt(JsonString *p, const char *zIn, u32 N){ N--; } while( zIn[0]=='0' && N>1 ){ + if( zIn[1]=='x' || zIn[1]=='X' ){ + sqlite3_int64 i = 0; + int rc = sqlite3DecOrHexToI64(zIn, &i); + if( rc<=1 ){ + jsonPrintf(100,p,"%lld",i); + }else if( rc==2 ){ + jsonAppendRaw(p, "9.0e999", 7); + }else{ + jsonAppendRaw(p, "9223372036854775808", 18); + } + return; + } zIn++; N--; } @@ -684,44 +696,32 @@ static void jsonReturn( } case JSON_INT: { sqlite3_int64 i = 0; + int rc; + int bNeg = 0; const char *z; + + assert( pNode->eU==1 ); z = pNode->u.zJContent; - if( z[0]=='-' ){ z++; } - while( z[0]>='0' && z[0]<='9' ){ - unsigned v = *(z++) - '0'; - if( i>=LARGEST_INT64/10 ){ - if( i>LARGEST_INT64/10 ) goto int_as_real; - if( z[0]>='0' && z[0]<='9' ) goto int_as_real; - if( v==9 ) goto int_as_real; - if( v==8 ){ - if( pNode->u.zJContent[0]=='-' ){ - sqlite3_result_int64(pCtx, SMALLEST_INT64); - goto int_done; - }else{ - goto int_as_real; - } - } - } - i = i*10 + v; + if( z[0]=='-' ){ z++; bNeg = 1; } + else if( z[0]=='+' ){ z++; } + rc = sqlite3DecOrHexToI64(z, &i); + if( rc<=1 ){ + sqlite3_result_int64(pCtx, bNeg ? -i : i); + }else if( rc==3 && bNeg ){ + sqlite3_result_int64(pCtx, SMALLEST_INT64); + }else{ + goto to_double; } - if( pNode->u.zJContent[0]=='-' ){ i = -i; } - sqlite3_result_int64(pCtx, i); - int_done: break; - int_as_real: ; /* no break */ deliberate_fall_through } case JSON_REAL: { double r; -#ifdef SQLITE_AMALGAMATION const char *z; assert( pNode->eU==1 ); + to_double: z = pNode->u.zJContent; sqlite3AtoF(z, &r, sqlite3Strlen30(z), SQLITE_UTF8); -#else - assert( pNode->eU==1 ); - r = strtod(pNode->u.zJContent, 0); -#endif sqlite3_result_double(pCtx, r); break; } @@ -1370,6 +1370,16 @@ json_parse_restart: if( c<'0' || c>'9' ) return -1; continue; } + if( (c=='x' || c=='X') + && (j==i+1 || (j==i+2 && (z[i]=='-' || z[i]=='+'))) + && z[j-1]=='0' + && sqlite3Isxdigit(z[j+1]) + ){ + assert( seenDP==0 ); + pParse->has5 = 1; + jnFlags |= JNODE_JSON5; + for(j=j+2; sqlite3Isxdigit(z[j]); j++){} + } break; } if( z[j-1]<'0' ){ diff --git a/src/util.c b/src/util.c index 72e8a18b2f..3d4e014382 100644 --- a/src/util.c +++ b/src/util.c @@ -843,7 +843,9 @@ int sqlite3DecOrHexToI64(const char *z, i64 *pOut){ u = u*16 + sqlite3HexToInt(z[k]); } memcpy(pOut, &u, 8); - return (z[k]==0 && k-i<=16) ? 0 : 2; + if( k-i>16 ) return 2; + if( z[k]!=0 ) return 1; + return 0; }else #endif /* SQLITE_OMIT_HEX_INTEGER */ {