[Libguestfs] [PATCH 1/3] generator: add a simple HTML escaping function

Pino Toscano ptoscano at redhat.com
Tue Feb 10 14:12:24 UTC 2015


---
 generator/utils.ml  | 8 +++++++-
 generator/utils.mli | 3 +++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/generator/utils.ml b/generator/utils.ml
index b24ba8c..3a62084 100644
--- a/generator/utils.ml
+++ b/generator/utils.ml
@@ -360,4 +360,10 @@ let args_of_optargs optargs =
     | OInt64 n -> Int64 n
     | OString n -> String n
     | OStringList n -> StringList n
-  ) optargs;
+  ) optargs
+
+let html_escape text =
+  let text = replace_str text "&" "&" in
+  let text = replace_str text "<" "<" in
+  let text = replace_str text ">" ">" in
+  text
diff --git a/generator/utils.mli b/generator/utils.mli
index 5fd40ce..e0f30c3 100644
--- a/generator/utils.mli
+++ b/generator/utils.mli
@@ -131,3 +131,6 @@ val spaces : int -> string
 
 val args_of_optargs : Types.optargs -> Types.args
 (** Convert a list of optargs into an equivalent list of args *)
+
+val html_escape : string -> string
+(** Escape a text for HTML display. *)
-- 
1.9.3




More information about the Libguestfs mailing list