When parsing JSON text into the BLOB format, only use node type JSONB_TEXTJ

for an unquoted object label if the object label contains escape sequences.

FossilOrigin-Name: a82ebbac3c542ec7f86d1e8414d7fd166db48450115ee3b26d12b5bb445f5896
This commit is contained in:
drh 2023-09-25 17:14:17 +00:00
parent 5933581cf0
commit 09f23d2a36
3 changed files with 29 additions and 12 deletions

View File

@ -1,5 +1,5 @@
C As\sa\stemporary\smeasure,\stry\sto\stranslate\sthe\sBLOB\sJSON\sformat\sinto\sthe\nlegacy\snode\sformat\sfor\sprocessing. C When\sparsing\sJSON\stext\sinto\sthe\sBLOB\sformat,\sonly\suse\snode\stype\sJSONB_TEXTJ\nfor\san\sunquoted\sobject\slabel\sif\sthe\sobject\slabel\scontains\sescape\ssequences.
D 2023-09-25T13:23:29.913 D 2023-09-25T17:14:17.033
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -670,7 +670,7 @@ F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51
F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6
F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71
F src/insert.c 3f0a94082d978bbdd33c38fefea15346c6c6bffb70bc645a71dc0f1f87dd3276 F src/insert.c 3f0a94082d978bbdd33c38fefea15346c6c6bffb70bc645a71dc0f1f87dd3276
F src/json.c 23efc117c4641118c2154938decc80fb3b29b1a420bcd0eaefe24ef808d1ada4 F src/json.c ee823133ed6f56ffb42c99fa78814667be70cd1b8106714cff459ee35f5a063e
F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa
F src/loadext.c 98cfba10989b3da6f1807ad42444017742db7f100a54f1032af7a8b1295912c0 F src/loadext.c 98cfba10989b3da6f1807ad42444017742db7f100a54f1032af7a8b1295912c0
F src/main.c 618aeb399e993cf561864f4b0cf6a331ee4f355cf663635f8d9da3193a46aa40 F src/main.c 618aeb399e993cf561864f4b0cf6a331ee4f355cf663635f8d9da3193a46aa40
@ -2121,8 +2121,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 8b53b2e6600c324ff7864840d98a3f03896b9792fcb60b70cc1f6227b3bd4ca1 P 14f2e95a9e531ef0d3fa7f1249f23c073a50c31b2109eefc2f258cada635ac2f
R 31821ddd534254fa82bb41b5d469060a R 0f073ae43da95216a48accf876602e9c
U drh U drh
Z 25f12fc9cea10e56c4709ee1d21954ff Z 7639209733392bafef0d3cec4e521036
# Remove this line to create a well-formed Fossil manifest. # Remove this line to create a well-formed Fossil manifest.

View File

@ -1 +1 @@
14f2e95a9e531ef0d3fa7f1249f23c073a50c31b2109eefc2f258cada635ac2f a82ebbac3c542ec7f86d1e8414d7fd166db48450115ee3b26d12b5bb445f5896

View File

@ -2465,6 +2465,21 @@ static void jsonBlobChangePayloadSize(
} }
} }
/*
** If z[0] is 'u' and is followed by exactly 4 hexadecimal character,
** then set *pOp to JSONB_TEXTJ and return true. If not, do not make
** any changes to *pOp and return false.
*/
static int jsonIs4HexB(const char *z, int *pOp){
if( z[0]!='u' ) return 0;
if( !sqlite3Isxdigit(z[1]) ) return 0;
if( !sqlite3Isxdigit(z[2]) ) return 0;
if( !sqlite3Isxdigit(z[3]) ) return 0;
if( !sqlite3Isxdigit(z[4]) ) return 0;
*pOp = JSONB_TEXTJ;
return 1;
}
/* /*
** Parse a single JSON text value which begins at pParse->zJson[i] into ** Parse a single JSON text value which begins at pParse->zJson[i] into
** its equivalent BLOB representation in pParse->aBlob[]. The parse is ** its equivalent BLOB representation in pParse->aBlob[]. The parse is
@ -2503,23 +2518,25 @@ json_parse_restart:
u32 iBlob = pParse->nBlob; u32 iBlob = pParse->nBlob;
x = jsonParseValueB(pParse, j); x = jsonParseValueB(pParse, j);
if( x<=0 ){ if( x<=0 ){
int op;
if( x==(-2) ){ if( x==(-2) ){
j = pParse->iErr; j = pParse->iErr;
if( pParse->nBlob!=(u32)iStart ) pParse->hasNonstd = 1; if( pParse->nBlob!=(u32)iStart ) pParse->hasNonstd = 1;
break; break;
} }
j += json5Whitespace(&z[j]); j += json5Whitespace(&z[j]);
if( sqlite3JsonId1(z[j]) op = JSONB_TEXT;
|| (z[j]=='\\' && z[j+1]=='u' && jsonIs4Hex(&z[j+2])) if( sqlite3JsonId1(z[j])
|| (z[j]=='\\' && jsonIs4HexB(&z[j+1], &op))
){ ){
int k = j+1; int k = j+1;
while( (sqlite3JsonId2(z[k]) && json5Whitespace(&z[k])==0) while( (sqlite3JsonId2(z[k]) && json5Whitespace(&z[k])==0)
|| (z[k]=='\\' && z[k+1]=='u' && jsonIs4Hex(&z[k+2])) || (z[k]=='\\' && jsonIs4HexB(&z[k+1], &op))
){ ){
k++; k++;
} }
assert( iBlob==pParse->nBlob ); assert( iBlob==pParse->nBlob );
jsonBlobAppendNodeType(pParse, JSONB_TEXTJ, k-j); jsonBlobAppendNodeType(pParse, op, k-j);
jsonBlobAppendNBytes(pParse, (const u8*)&z[j], k-j); jsonBlobAppendNBytes(pParse, (const u8*)&z[j], k-j);
pParse->hasNonstd = 1; pParse->hasNonstd = 1;
x = k; x = k;
@ -3276,7 +3293,7 @@ static int jsonParseValueFromBinary(JsonParse *pParse, u32 i){
break; break;
} }
case JSONB_TEXTJ: { case JSONB_TEXTJ: {
jsonParseAddNode(pParse, JSON_STRING | (JNODE_RAW<<8), sz, zPayload); jsonParseAddNode(pParse, JSON_STRING | (JNODE_ESCAPE<<8), sz, zPayload);
break; break;
} }
case JSONB_TEXT5: { case JSONB_TEXT5: {