From 5063ae307001dcddbfcc60e7abda04cf98bffeb4 Mon Sep 17 00:00:00 2001 From: Bernhard Schommer Date: Thu, 8 Mar 2018 17:52:31 +0100 Subject: Perform quoting for json. The strings for json need quoting of special characters such as \" and \\. Bug 22438 --- backend/AisAnnot.ml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'backend/AisAnnot.ml') diff --git a/backend/AisAnnot.ml b/backend/AisAnnot.ml index 5983f417..27005561 100644 --- a/backend/AisAnnot.ml +++ b/backend/AisAnnot.ml @@ -163,7 +163,14 @@ let json_ais_annot preg_string sp_reg_name txt args = let txt = ais_annot_txt false 0 preg_string sp_reg_name txt args in let t_to_json = function | Label _ -> String "%here" - | s -> s in + | String s -> let buf = Buffer.create (String.length s) in + String.iter (fun c -> + begin match c with + | '\\' | '"' -> Buffer.add_char buf '\\' + | _ -> () end; + Buffer.add_char buf c) s; + String (Buffer.contents buf) + | Symbol s -> Symbol s in (List.map t_to_json txt) let validate_ais_annot env loc txt args = -- cgit