1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-09 14:21:03 +03:00

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
This commit is contained in:
drh
2023-12-06 16:57:18 +00:00
parent 8dfbf4addc
commit 9df01b5ccf
4 changed files with 24 additions and 19 deletions

View File

@@ -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;