diff options
author | drh <drh@noemail.net> | 2019-09-14 00:21:34 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2019-09-14 00:21:34 +0000 |
commit | fab5b07395796f7761dbf3ba8604325889af9522 (patch) | |
tree | 9c07e1e7bf82c5682011cbcc66a00c45146c1aa9 /ext/misc/json1.c | |
parent | 51a75aaa76c300b3826e434013ddaf73c49e57c1 (diff) | |
download | sqlite-fab5b07395796f7761dbf3ba8604325889af9522.tar.gz sqlite-fab5b07395796f7761dbf3ba8604325889af9522.zip |
Fix the windows inverse function on the JSON aggregates.
FossilOrigin-Name: f464d847af490dd3ec45565dcc4c2e6ff4ed1ebb65036f30ca0b3ce2e73080e6
Diffstat (limited to 'ext/misc/json1.c')
-rw-r--r-- | ext/misc/json1.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/ext/misc/json1.c b/ext/misc/json1.c index b3130eaf0..251fd14af 100644 --- a/ext/misc/json1.c +++ b/ext/misc/json1.c @@ -1820,7 +1820,7 @@ static void jsonArrayStep( if( pStr->zBuf==0 ){ jsonInit(pStr, ctx); jsonAppendChar(pStr, '['); - }else{ + }else if( pStr->nUsed>1 ){ jsonAppendChar(pStr, ','); pStr->pCtx = ctx; } @@ -1870,7 +1870,9 @@ static void jsonGroupInverse( ){ int i; int inStr = 0; + int nNest = 0; char *z; + char c; JsonString *pStr; UNUSED_PARAM(argc); UNUSED_PARAM(argv); @@ -1881,12 +1883,18 @@ static void jsonGroupInverse( if( NEVER(!pStr) ) return; #endif z = pStr->zBuf; - for(i=1; z[i]!=',' || inStr; i++){ - assert( i<pStr->nUsed ); - if( z[i]=='"' ){ + for(i=1; (c = z[i])!=',' || inStr || nNest; i++){ + if( i>=pStr->nUsed ){ + pStr->nUsed = 1; + return; + } + if( c=='"' ){ inStr = !inStr; - }else if( z[i]=='\\' ){ + }else if( c=='\\' ){ i++; + }else if( !inStr ){ + if( c=='{' || c=='[' ) nNest++; + if( c=='}' || c==']' ) nNest--; } } pStr->nUsed -= i; @@ -1916,7 +1924,7 @@ static void jsonObjectStep( if( pStr->zBuf==0 ){ jsonInit(pStr, ctx); jsonAppendChar(pStr, '{'); - }else{ + }else if( pStr->nUsed>1 ){ jsonAppendChar(pStr, ','); pStr->pCtx = ctx; } |