From 94e22bc07737e6b4ef0ba7a6a7c901a1c16d9edc Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 10 May 2025 17:09:53 +0000 Subject: Provide the SQLITE_BUG_COMPATIBLE_20250510 compile-time option that restores the JSON5 bug fixed in the previous check-in, in case some applications need it for legacy compatibility. FossilOrigin-Name: 491cf31904fdbc9567b838d1ba27901e75f8ea3a117043017d08354bb09f9711 --- src/json.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/json.c') diff --git a/src/json.c b/src/json.c index e1b019d78..ee4cf1cbc 100644 --- a/src/json.c +++ b/src/json.c @@ -1757,7 +1757,11 @@ json_parse_restart: || (c=='u' && jsonIs4Hex(&z[j+1])) ){ if( opcode==JSONB_TEXT ) opcode = JSONB_TEXTJ; }else if( c=='\'' || c=='v' || c=='\n' - || (c=='0' && !sqlite3Isdigit(z[j+1])) +#ifdef SQLITE_BUG_COMPATIBLE_20250510 + || (c=='0') /* Legacy bug compatible */ +#else + || (c=='0' && !sqlite3Isdigit(z[j+1])) /* Correct implementation */ +#endif || (0xe2==(u8)c && 0x80==(u8)z[j+1] && (0xa8==(u8)z[j+2] || 0xa9==(u8)z[j+2])) || (c=='x' && jsonIs2Hex(&z[j+1])) ){ @@ -2726,7 +2730,18 @@ static u32 jsonUnescapeOneChar(const char *z, u32 n, u32 *piOut){ case 't': { *piOut = '\t'; return 2; } case 'v': { *piOut = '\v'; return 2; } case '0': { + /* JSON5 requires that the \0 escape not be followed by a digit. + ** But SQLite did not enforce this restriction in versions 3.42.0 + ** through 3.49.2. That was a bug. But some applications might have + ** come to depend on that bug. Use the SQLITE_BUG_COMPATIBLE_20250510 + ** option to restore the old buggy behavior. */ +#ifdef SQLITE_BUG_COMPATIBLE_20250510 + /* Legacy bug-compatible behavior */ + *piOut = 0; +#else + /* Correct behavior */ *piOut = (n>2 && sqlite3Isdigit(z[2])) ? JSON_INVALID_CHAR : 0; +#endif return 2; } case '\'': -- cgit v1.2.3