aboutsummaryrefslogtreecommitdiff
path: root/ext/misc/json1.c
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2015-09-22 00:21:03 +0000
committerdrh <drh@noemail.net>2015-09-22 00:21:03 +0000
commit8cb0c83cce2abc8e0a303877253ca17a19d6017a (patch)
tree56f851d506b045dcf4494dceaa7c18c25835982a /ext/misc/json1.c
parent357e42d48fc842fc0974313b3cb5b69bc859bc78 (diff)
downloadsqlite-8cb0c83cce2abc8e0a303877253ca17a19d6017a.tar.gz
sqlite-8cb0c83cce2abc8e0a303877253ca17a19d6017a.zip
Fix json_set() so that it can overwrite a value that was previously overwritten
during the same call. FossilOrigin-Name: 0f16041647993975c316203c7e11f06e27640136
Diffstat (limited to 'ext/misc/json1.c')
-rw-r--r--ext/misc/json1.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/ext/misc/json1.c b/ext/misc/json1.c
index 4e21b151a..c3e21dd50 100644
--- a/ext/misc/json1.c
+++ b/ext/misc/json1.c
@@ -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++;