From 8d5be14e9cd68dcf59cc7c5715cb28c1646416da Mon Sep 17 00:00:00 2001 From: Andrzej Kotulski Date: Tue, 14 Mar 2017 12:21:45 -0700 Subject: [PATCH] [backend] Escape URLs to fix html output Reviewed By: jeremydubreil Differential Revision: D4707377 fbshipit-source-id: cbbccdc --- infer/src/IR/Io_infer.ml | 3 ++- infer/src/base/Escape.ml | 23 +++++++++++++++++++++++ infer/src/base/Escape.mli | 3 +++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/infer/src/IR/Io_infer.ml b/infer/src/IR/Io_infer.ml index 203c60271..2ea24820b 100644 --- a/infer/src/IR/Io_infer.ml +++ b/infer/src/IR/Io_infer.ml @@ -174,8 +174,9 @@ struct let pos_str = match pos with | None -> "" | Some s -> "#" ^ s in + let escaped_path = List.map ~f:Escape.escape_url path in let link_str = - (DB.filename_to_string (DB.Results_dir.path_to_filename DB.Results_dir.Rel path)) + (DB.filename_to_string (DB.Results_dir.path_to_filename DB.Results_dir.Rel escaped_path)) ^ ".html" ^ pos_str in let name_str = match name with diff --git a/infer/src/base/Escape.ml b/infer/src/base/Escape.ml index 99691ccb4..62f49e36b 100644 --- a/infer/src/base/Escape.ml +++ b/infer/src/base/Escape.ml @@ -44,6 +44,29 @@ let escape_xml s = | _ -> None in escape_map map s +let escape_url s = + let map = function + | '!' -> Some "%21" + | '#' -> Some "%23" + | '$' -> Some "%24" + | '&' -> Some "%26" + | '\'' -> Some "%27" + | '(' -> Some "%28" + | ')' -> Some "%29" + | '*' -> Some "%2A" + | '+' -> Some "%2B" + | ',' -> Some "%2C" + | '/' -> Some "%2F" + | ':' -> Some "%3A" + | ';' -> Some "%3B" + | '=' -> Some "%3D" + | '?' -> Some "%3F" + | '@' -> Some "%40" + | '[' -> Some "%5B" + | ']' -> Some "%5D" + | _ -> None in + escape_map map s + let escape_dotty s = let map = function | '"' -> Some "\\\"" diff --git a/infer/src/base/Escape.mli b/infer/src/base/Escape.mli index d02e37d90..e91dd3741 100644 --- a/infer/src/base/Escape.mli +++ b/infer/src/base/Escape.mli @@ -27,5 +27,8 @@ val escape_path : string -> string (** escape a string to be used in an xml file *) val escape_xml : string -> string + +val escape_url : string -> string + (** escape a string to be used as a file name *) val escape_filename : string -> string