diff options
author | drh <> | 2023-12-07 14:09:25 +0000 |
---|---|---|
committer | drh <> | 2023-12-07 14:09:25 +0000 |
commit | 5a238ffcae3e670424797224296c651c2457f922 (patch) | |
tree | d2782e9c9d09f16fe1b0a88ca84638147acda9d6 /src/json.c | |
parent | f86a07b0c42070d4f35a857857d09397676b86d0 (diff) | |
download | sqlite-5a238ffcae3e670424797224296c651c2457f922.tar.gz sqlite-5a238ffcae3e670424797224296c651c2457f922.zip |
Rework the jsonEachPathLength() routine in json_tree() so that it is
less susceptible to problems due to goofy object labels.
FossilOrigin-Name: 858b76a00e8ff55215f7a2e6a4cd77fc4d4f98dea7224cd90488744f5ce246a4
Diffstat (limited to 'src/json.c')
-rw-r--r-- | src/json.c | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/src/json.c b/src/json.c index 850e2241e..6a4a0babf 100644 --- a/src/json.c +++ b/src/json.c @@ -4521,23 +4521,20 @@ static int jsonEachNext(sqlite3_vtab_cursor *cur){ */ static int jsonEachPathLength(JsonEachCursor *p){ u32 n = p->path.nUsed; - const char *z = p->path.zBuf; - if( p->iRowid==0 && p->bRecursive && n>1 ){ - if( z[n-1]==']' ){ - do{ - assert( n>1 ); - n--; - }while( z[n]!='[' ); - }else if( z[n-1]=='"' ){ - do{ - assert( n>1 ); - n--; - }while( z[n]!='.' || z[n+1]!='"' ); - }else{ - do{ - assert( n>1 ); - n--; - }while( z[n]!='.' ); + char *z = p->path.zBuf; + if( p->iRowid==0 && p->bRecursive && n>=2 ){ + while( n>1 ){ + n--; + if( z[n]=='[' || z[n]=='.' ){ + u32 x, sz = 0; + char cSaved = z[n]; + z[n] = 0; + assert( p->sParse.eEdit==0 ); + x = jsonLookupStep(&p->sParse, 0, z+1, 0); + z[n] = cSaved; + if( JSON_LOOKUP_ISERROR(x) ) continue; + if( x + jsonbPayloadSize(&p->sParse, x, &sz) == p->i ) break; + } } } return n; |