Skip to content
Myr

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

Before adoption: this commit came in with the history the project adopted, so no landing records it.

In order for a string literal to be valid in JSON, the value must be surrounded by double quotes.

authored by Matt Meyers · committed by GitHub · parent 1bebd23 · Browse files · 2 files+5 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+5 added−0 removed

  • tests:+3 added−0 removed
  • other:+2 added−0 removed

2 files+5 added−0 removed

modified:src/jv_parse.c+2 added
510 unmodified lines
511 jv v;512 switch (p->tokenbuf[0]) {513 case 't': pattern = "true"; plen = 4; v = jv_true(); break;514 case 'f': pattern = "false"; plen = 5; v = jv_false(); break;515 case '\'':516 return "Invalid string literal; expected \", but got '";517 case 'n':518 // if it starts with 'n', it could be a literal "nan"519 if (p->tokenbuf[1] == 'u') {520 pattern = "null"; plen = 4; v = jv_null();
393 unmodified lines
modified:tests/jq.test+3 added
2185 unmodified lines
2186try ["ok", setpath([1]; 1)] catch ["ko", .]2187{"hi":"hello"}2188["ko","Cannot index object with number"]21892190try fromjson catch .2191"{'a': 123}"2192"Invalid string literal; expected \", but got ' at line 1, column 5 (while parsing '{'a': 123}')"21932194# ltrimstr/1 rtrimstr/1 don't leak on invalid input #297721952196try ltrimstr(1) catch "x", try rtrimstr(1) catch "x" | "ok"
31 unmodified lines