diff options
author | drh <> | 2023-12-06 16:57:18 +0000 |
---|---|---|
committer | drh <> | 2023-12-06 16:57:18 +0000 |
commit | 9df01b5ccf78535dd44e1f8c0b83fcee40ea5042 (patch) | |
tree | e014ef69e82f9db4ea3b8126e9116937910bb138 /src/json.c | |
parent | 8dfbf4addce7f8bf4d4fa3fd96a41aea11d9b41d (diff) | |
download | sqlite-9df01b5ccf78535dd44e1f8c0b83fcee40ea5042.tar.gz sqlite-9df01b5ccf78535dd44e1f8c0b83fcee40ea5042.zip |
Fix the routine that determines the json_tree.path value for the first row
so that it correctly takes into account escape sequences in the path
argument.
FossilOrigin-Name: b9243ee8a37c62eb8848e765bd4af83bc1b3d3eb24fb4268a1357ad1f8b2e1fb
Diffstat (limited to 'src/json.c')
-rw-r--r-- | src/json.c | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/src/json.c b/src/json.c index 44abe2d16..c9014f74a 100644 --- a/src/json.c +++ b/src/json.c @@ -4489,22 +4489,23 @@ 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( p->path.zBuf[n-1]==']' ){ + if( z[n-1]==']' ){ do{ - assert( n>0 ); + assert( n>1 ); n--; - }while( p->path.zBuf[n]!='[' ); + }while( z[n]!='[' ); + }else if( z[n-1]=='"' ){ + do{ + assert( n>1 ); + n--; + }while( z[n]!='.' || z[n+1]!='"' ); }else{ - u32 sz = 0; - jsonbPayloadSize(&p->sParse, p->i, &sz); - if( p->path.zBuf[n-1]=='"' ) sz += 2; - assert( sz<n ); - n -= sz; - while( p->path.zBuf[n]!='.' && ALWAYS(n>0) ){ + do{ + assert( n>1 ); n--; - assert( n>0 ); - } + }while( z[n]!='.' ); } } return n; |