]> git.eshelyaron.com Git - emacs.git/commitdiff
Don't signal `json-end-of-file` for short nonempty bad JSON inputs
authorMattias EngdegÄrd <mattiase@acm.org>
Sun, 31 Mar 2024 17:19:58 +0000 (19:19 +0200)
committerEshel Yaron <me@eshelyaron.com>
Tue, 2 Apr 2024 13:27:14 +0000 (15:27 +0200)
* src/json.c (json_parse_value): Generate a plain parse error.
* test/src/json-tests.el (json-parse-string/short): Adapt test.

(cherry picked from commit 3f4486dd76c44c76c58605fb9a1643515133ff3f)

src/json.c
test/src/json-tests.el

index 8749009a24b92dcdeeac8a8f5bf7c2c6ee0d2caa..ca9be26cd9ff73ee5058d6781be00fbfe5c387a3 100644 (file)
@@ -1655,9 +1655,9 @@ json_parse_value (struct json_parser *parser, int c)
     return json_parse_number (parser, c);
   else
     {
-      int c2 = json_input_get (parser);
-      int c3 = json_input_get (parser);
-      int c4 = json_input_get (parser);
+      int c2 = json_input_get_if_possible (parser);
+      int c3 = json_input_get_if_possible (parser);
+      int c4 = json_input_get_if_possible (parser);
       int c5 = json_input_get_if_possible (parser);
 
       if (c == 't' && c2 == 'r' && c3 == 'u' && c4 == 'e'
index a1bafadaa872f690978a60376b1d7a39a5ea2359..628a5a3de575dbcec40fc5a9415cfeebc001ff5e 100644 (file)
   (should-error (json-serialize ["u\u00C4\xCCv"]) :type 'wrong-type-argument))
 
 (ert-deftest json-parse-string/short ()
-  :expected-result :failed
   (should-error (json-parse-string "") :type 'json-end-of-file)
   (should-error (json-parse-string " ") :type 'json-end-of-file)
-  ;; BUG: currently results in `json-end-of-file' for short non-empty inputs.
-  (dolist (s '("a" "ab" "abc" "abcd"
+  (dolist (s '("a" "ab" "abc" "abcd" "\0" "\1"
                "t" "tr" "tru" "truE" "truee"
                "n" "nu" "nul" "nulL" "nulll"
                "f" "fa" "fal" "fals" "falsE" "falsee"))