Commit 36794a60cf2a9739d4e1b021c9ba00feef9d42da

Authored by Jay Berkenbilt
1 parent e7ecc348

Allow \/ in a json string

ChangeLog
  1 +2022-02-25 Jay Berkenbilt <ejb@ql.org>
  2 +
  3 + * Bug fix in JSON parser: accept \/ in a string as valid input per
  4 + JSON spec even though we don't translate / to \/ on output.
  5 +
1 2022-02-22 Jay Berkenbilt <ejb@ql.org> 6 2022-02-22 Jay Berkenbilt <ejb@ql.org>
2 7
3 * Recognize PDF strings explicitly marked as UTF-8 as allowed by 8 * Recognize PDF strings explicitly marked as UTF-8 as allowed by
libqpdf/JSON.cc
@@ -629,6 +629,9 @@ JSONParser::decode_string(std::string const&amp; str) @@ -629,6 +629,9 @@ JSONParser::decode_string(std::string const&amp; str)
629 { 629 {
630 case '\\': 630 case '\\':
631 case '\"': 631 case '\"':
  632 + case '/':
  633 + // \/ is allowed in json input, but so is /, so we
  634 + // don't map / to \/ in output.
632 result.append(1, ch); 635 result.append(1, ch);
633 break; 636 break;
634 case 'b': 637 case 'b':
@@ -875,7 +878,7 @@ void JSONParser::getToken() @@ -875,7 +878,7 @@ void JSONParser::getToken()
875 878
876 case ls_backslash: 879 case ls_backslash:
877 /* cSpell: ignore bfnrt */ 880 /* cSpell: ignore bfnrt */
878 - if (strchr("\\\"bfnrt", *p)) 881 + if (strchr("\\\"/bfnrt", *p))
879 { 882 {
880 lex_state = ls_string; 883 lex_state = ls_string;
881 } 884 }
libtests/qtest/json_parse/good-01.json
1 {"a": "bcd", "e": [1, 1 {"a": "bcd", "e": [1,
2 2, 3,4,"five", {"six": 7, "8": 9}, null, true, 2 2, 3,4,"five", {"six": 7, "8": 9}, null, true,
3 - false]} 3 + false, "a\b\f\n\r\t\\\"\/z"]}
libtests/qtest/json_parse/save-01.json
@@ -12,6 +12,7 @@ @@ -12,6 +12,7 @@
12 }, 12 },
13 null, 13 null,
14 true, 14 true,
15 - false 15 + false,
  16 + "a\b\f\n\r\t\\\"/z"
16 ] 17 ]
17 } 18 }