Return error for string literal beginning with single quote (#2964)

In order for a string literal to be valid in JSON, the value must be
surrounded by double quotes.
This commit is contained in:
Matt Meyers authored and GitHub committed 2024-10-06 08:52:56 +09:00
1 parent 1bebd23aad
commit 562d5c5222
2 files changed
+5

No files matched your search

+2
View File
@@ -512,6 +512,8 @@ static pfunc check_literal(struct jv_parser* p) {
switch (p->tokenbuf[0]) {
case 't': pattern = "true"; plen = 4; v = jv_true(); break;
case 'f': pattern = "false"; plen = 5; v = jv_false(); break;
case '\'':
return "Invalid string literal; expected \", but got '";
case 'n':
// if it starts with 'n', it could be a literal "nan"
if (p->tokenbuf[1] == 'u') {
+3
View File
@@ -2187,6 +2187,9 @@ try ["ok", setpath([1]; 1)] catch ["ko", .]
{"hi":"hello"}
["ko","Cannot index object with number"]
try fromjson catch .
"{'a': 123}"
"Invalid string literal; expected \", but got ' at line 1, column 5 (while parsing '{'a': 123}')"
# ltrimstr/1 rtrimstr/1 don't leak on invalid input #2977