Fossil SCM

Fix the JSON string encoder so that it works for non-BMP unicode characters.

drh 2021-01-14 20:51 trunk
Commit 006b908e0cdc19d8a8722c8508dba5d1a1a89d344b5facd24773e9ef94b880da
1 file changed +4 -4
+4 -4
--- src/encode.c
+++ src/encode.c
@@ -401,14 +401,14 @@
401401
char *zOut;
402402
u32 c;
403403
int n, i, j;
404404
z = (const unsigned char*)zStr;
405405
n = 0;
406
- while( (c = fossil_utf8_read(&z))!=0 ){
406
+ while( (c = *(z++))!=0 ){
407407
if( c=='\\' || c=='"' ){
408408
n += 2;
409
- }else if( c<' ' || c>=0x7f ){
409
+ }else if( c<' ' ){
410410
if( c=='\n' || c=='\r' ){
411411
n += 2;
412412
}else{
413413
n += 6;
414414
}
@@ -424,15 +424,15 @@
424424
z = (const unsigned char*)zStr;
425425
i = 0;
426426
if(fAddQuotes){
427427
zOut[i++] = '"';
428428
}
429
- while( (c = fossil_utf8_read(&z))!=0 ){
429
+ while( (c = *(z++))!=0 ){
430430
if( c=='\\' || c=='"' ){
431431
zOut[i++] = '\\';
432432
zOut[i++] = c;
433
- }else if( c<' ' || c>=0x7f ){
433
+ }else if( c<' ' ){
434434
zOut[i++] = '\\';
435435
if( c=='\n' ){
436436
zOut[i++] = 'n';
437437
}else if( c=='\r' ){
438438
zOut[i++] = 'r';
439439
--- src/encode.c
+++ src/encode.c
@@ -401,14 +401,14 @@
401 char *zOut;
402 u32 c;
403 int n, i, j;
404 z = (const unsigned char*)zStr;
405 n = 0;
406 while( (c = fossil_utf8_read(&z))!=0 ){
407 if( c=='\\' || c=='"' ){
408 n += 2;
409 }else if( c<' ' || c>=0x7f ){
410 if( c=='\n' || c=='\r' ){
411 n += 2;
412 }else{
413 n += 6;
414 }
@@ -424,15 +424,15 @@
424 z = (const unsigned char*)zStr;
425 i = 0;
426 if(fAddQuotes){
427 zOut[i++] = '"';
428 }
429 while( (c = fossil_utf8_read(&z))!=0 ){
430 if( c=='\\' || c=='"' ){
431 zOut[i++] = '\\';
432 zOut[i++] = c;
433 }else if( c<' ' || c>=0x7f ){
434 zOut[i++] = '\\';
435 if( c=='\n' ){
436 zOut[i++] = 'n';
437 }else if( c=='\r' ){
438 zOut[i++] = 'r';
439
--- src/encode.c
+++ src/encode.c
@@ -401,14 +401,14 @@
401 char *zOut;
402 u32 c;
403 int n, i, j;
404 z = (const unsigned char*)zStr;
405 n = 0;
406 while( (c = *(z++))!=0 ){
407 if( c=='\\' || c=='"' ){
408 n += 2;
409 }else if( c<' ' ){
410 if( c=='\n' || c=='\r' ){
411 n += 2;
412 }else{
413 n += 6;
414 }
@@ -424,15 +424,15 @@
424 z = (const unsigned char*)zStr;
425 i = 0;
426 if(fAddQuotes){
427 zOut[i++] = '"';
428 }
429 while( (c = *(z++))!=0 ){
430 if( c=='\\' || c=='"' ){
431 zOut[i++] = '\\';
432 zOut[i++] = c;
433 }else if( c<' ' ){
434 zOut[i++] = '\\';
435 if( c=='\n' ){
436 zOut[i++] = 'n';
437 }else if( c=='\r' ){
438 zOut[i++] = 'r';
439

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button