Skip to content

Commit 562d5c5

Browse files
authored
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.
1 parent 1bebd23 commit 562d5c5

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

src/jv_parse.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,8 @@ static pfunc check_literal(struct jv_parser* p) {
512512
switch (p->tokenbuf[0]) {
513513
case 't': pattern = "true"; plen = 4; v = jv_true(); break;
514514
case 'f': pattern = "false"; plen = 5; v = jv_false(); break;
515+
case '\'':
516+
return "Invalid string literal; expected \", but got '";
515517
case 'n':
516518
// if it starts with 'n', it could be a literal "nan"
517519
if (p->tokenbuf[1] == 'u') {

tests/jq.test

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2187,6 +2187,9 @@ try ["ok", setpath([1]; 1)] catch ["ko", .]
21872187
{"hi":"hello"}
21882188
["ko","Cannot index object with number"]
21892189

2190+
try fromjson catch .
2191+
"{'a': 123}"
2192+
"Invalid string literal; expected \", but got ' at line 1, column 5 (while parsing '{'a': 123}')"
21902193

21912194
# ltrimstr/1 rtrimstr/1 don't leak on invalid input #2977
21922195

0 commit comments

Comments
 (0)