From 1b07e7b1e1b8a81197e98a71baf9c51579f48a3f Mon Sep 17 00:00:00 2001 From: Simon Van Casteren Date: Fri, 13 Dec 2019 19:35:58 +0100 Subject: Fixed JSON parsing: newline escaping --- src/json.sml | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/json.sml b/src/json.sml index 4f604cc4..81d7b8b4 100644 --- a/src/json.sml +++ b/src/json.sml @@ -121,12 +121,18 @@ struct if peek () = #"\\" andalso (String.sub (!inputData, 1)) = #"\"" then (consume "\\\""; pickChars (s ^ "\"")) else - if peek () = #"\\" andalso (String.sub (!inputData, 1)) = #"n" - then (consume "\\n"; pickChars (s ^ "\n")) + if peek () = #"\\" andalso String.sub (!inputData, 1) = #"\\" andalso String.sub (!inputData, 2) = #"n" + then (consume "\\\\n"; pickChars (s ^ "\\n")) else - if peek () = #"\\" andalso (String.sub (!inputData, 1)) = #"r" - then (consume "\\r"; pickChars (s ^ "\r")) - else pickChars (s ^ String.str (take ())) + if peek () = #"\\" andalso (String.sub (!inputData, 1)) = #"n" + then (consume "\\n"; pickChars (s ^ "\n")) + else + if peek () = #"\\" andalso String.sub (!inputData, 1) = #"\\" andalso String.sub (!inputData, 2) = #"r" + then (consume "\\\\r"; pickChars (s ^ "\\r")) + else + if peek () = #"\\" andalso (String.sub (!inputData, 1)) = #"r" + then (consume "\\r"; pickChars (s ^ "\r")) + else pickChars (s ^ String.str (take ())) in pickChars "" end -- cgit v1.2.3