Fix json_set() so that it can overwrite a value that was previously overwritten

during the same call.

FossilOrigin-Name: 0f16041647993975c316203c7e11f06e27640136
This commit is contained in:
drh 2015-09-22 00:21:03 +00:00
parent 357e42d48f
commit 8cb0c83cce
4 changed files with 27 additions and 12 deletions

View File

@ -807,6 +807,20 @@ static int jsonParseFindParents(JsonParse *pParse){
return SQLITE_OK;
}
/*
** Compare the OBJECT label at pNode against zKey,nKey. Return true on
** a match.
*/
static int jsonLabelCompare(JsonNode *pNode, const char *zKey, int nKey){
if( pNode->jnFlags & JNODE_RAW ){
if( pNode->n!=nKey ) return 0;
return strncmp(pNode->u.zJContent, zKey, nKey)==0;
}else{
if( pNode->n!=nKey+2 ) return 0;
return strncmp(pNode->u.zJContent+1, zKey, nKey)==0;
}
}
/* forward declaration */
static JsonNode *jsonLookupAppend(JsonParse*,const char*,int*,const char**);
@ -855,9 +869,7 @@ static JsonNode *jsonLookupStep(
j = 1;
for(;;){
while( j<=pRoot->n ){
if( pRoot[j].n==nKey+2
&& strncmp(&pRoot[j].u.zJContent[1],zKey,nKey)==0
){
if( jsonLabelCompare(pRoot+j, zKey, nKey) ){
return jsonLookupStep(pParse, iRoot+j+1, &zPath[i], pApnd, pzErr);
}
j++;

View File

@ -1,5 +1,5 @@
C For\sMSVC,\shave\sthe\s'sqlite3.c'\starget\sdepend\son\s'sqlite3ext.h'\sas\swell\sas\sother\stargets\smay\sdepend\son\sthis\sbehavior\s(e.g.\sextensions).
D 2015-09-21T23:53:42.233
C Fix\sjson_set()\sso\sthat\sit\scan\soverwrite\sa\svalue\sthat\swas\spreviously\soverwritten\nduring\sthe\ssame\scall.
D 2015-09-22T00:21:03.350
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 2047811644c5bac91ccdfc2720e49b60965a63a7
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -195,7 +195,7 @@ F ext/misc/eval.c f971962e92ebb8b0a4e6b62949463ee454d88fa2
F ext/misc/fileio.c d4171c815d6543a9edef8308aab2951413cd8d0f
F ext/misc/fuzzer.c 4c84635c71c26cfa7c2e5848cf49fe2d2cfcd767
F ext/misc/ieee754.c b0362167289170627659e84173f5d2e8fee8566e
F ext/misc/json1.c 54f067ea34f6a7426b998ca0fb411d2eefaeb25e
F ext/misc/json1.c c5e7018b8fe23ba778a24d918724b5963ecaa689
F ext/misc/nextchar.c 35c8b8baacb96d92abbb34a83a997b797075b342
F ext/misc/percentile.c bcbee3c061b884eccb80e21651daaae8e1e43c63
F ext/misc/regexp.c af92cdaa5058fcec1451e49becc7ba44dba023dc
@ -815,7 +815,7 @@ F test/journal3.test ff8af941f9e06161d3db1b46bb9f965ff0e7f307
F test/jrnlmode.test 7864d59cf7f6e552b9b99ba0f38acd167edc10fa
F test/jrnlmode2.test 81610545a4e6ed239ea8fa661891893385e23a1d
F test/jrnlmode3.test 556b447a05be0e0963f4311e95ab1632b11c9eaa
F test/json101.test b33f38882794a3e3f6f1c39f2f1c55a0e8aaf56d
F test/json101.test bfc81e4bdb412a1659160a4284448bd212ba6df1
F test/json102.test 796b1c59894c6e0f38fc1a3acb0e690573b952a3
F test/keyword1.test 37ef6bba5d2ed5b07ecdd6810571de2956599dff
F test/lastinsert.test 42e948fd6442f07d60acbd15d33fb86473e0ef63
@ -1387,7 +1387,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
P 17150ada1474e70d7c5ffe6ba5667f45671a434b
R 82ab9439819ba02031a617b27cced325
U mistachkin
Z aaf6fe237967240a8a938b8bfbc1f2fb
P 737ac3faf4e5fcb5855f5f9a1c1ddfc5424e6292
R 95f992a7687b0db3b0df98a691005bc0
U drh
Z 7a61ae480ab77880b942dd9dc8577d84

View File

@ -1 +1 @@
737ac3faf4e5fcb5855f5f9a1c1ddfc5424e6292
0f16041647993975c316203c7e11f06e27640136

View File

@ -74,6 +74,9 @@ do_execsql_test json1-3.3 {
do_execsql_test json1-3.4 {
SELECT json_type(json_set('{"a":1,"b":2}','$.b',json('{"x":3,"y":4}')),'$.b');
} {object}
do_execsql_test json1-3.5 {
SELECT fullkey, atom, '|' FROM json_tree(json_set('{}','$.x',123,'$.x',456));
} {{$} {} | {$.x} 456 |}
# Per rfc7159, any JSON value is allowed at the top level, and whitespace
# is permitting before and/or after that value.