From a9835d6c37d2a3c762c4620294d0b2a13d543ccb Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 20 Jun 2021 09:07:45 -0700 Subject: read/get-json: reject trailing junk in string input. * parser.c (lisp_parse_impl): If parsing from string, check for trailing junk and diagnose. JSON parsing doesn't use lookahead because it doesn't have a.b syntax, so the recent_tok gives the last token that actually went into the syntax, and not a lookahead token. So in the case of JSON, we call yylex to see if there is any trailing token. * tests/010/json.tl: Extend get-json tests to more kinds of objects, and then replicate with trailing whitespace and trailing junk to provide coverage for these cases. * tests/012/parse.t: Slew of new read tests and iread also. * txr.1: Documented. --- tests/010/json.tl | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'tests/010/json.tl') diff --git a/tests/010/json.tl b/tests/010/json.tl index 29ee2833..8d414b2e 100644 --- a/tests/010/json.tl +++ b/tests/010/json.tl @@ -92,7 +92,27 @@ (get-json "\"abc\"") "abc" (get-json "true") t (get-json "false") nil - (get-json "null") null) + (get-json "null") null + (get-json "[1,2,3]") #(1.0 2.0 3.0) + (get-json "{\"a\":\"b\"}") #H(() ("a" "b"))) + +(mtest + (get-json "0 \n") 0.0 + (get-json "\"abc\" \n") "abc" + (get-json "true \n") t + (get-json "false \n") nil + (get-json "null \n") null + (get-json "[1,2,3] \n") #(1.0 2.0 3.0) + (get-json "{\"a\":\"b\"} \n") #H(() ("a" "b"))) + +(mtest + (get-json "0,") :error + (get-json "\"abc\",") :error + (get-json "true,") :error + (get-json "false,") :error + (get-json "null,") :error + (get-json "[1,2,3],") :error + (get-json "{\"a\":\"b\"},") :error) (mtest (tojson #(1.0 "abc" t)) "[1,\"abc\",true]" -- cgit v1.2.3