From 2e00cd0bdfadfab33a3c802994c8c0e5cf565174 Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Thu, 17 Jul 2008 13:33:56 -0400 Subject: Proper escaping of cdata --- src/mono_opt.sml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/mono_opt.sml') diff --git a/src/mono_opt.sml b/src/mono_opt.sml index aa2c5234..81e42b56 100644 --- a/src/mono_opt.sml +++ b/src/mono_opt.sml @@ -46,6 +46,7 @@ fun attrifyFloat n = Real.toString n val attrifyString = String.translate (fn #"\"" => """ + | #"&" => "&" | ch => if Char.isPrint ch then str ch else @@ -54,6 +55,15 @@ val attrifyString = String.translate (fn #"\"" => """ val urlifyInt = attrifyInt val urlifyFloat = attrifyFloat +val htmlifyString = String.translate (fn ch => case ch of + #"<" => "<" + | #"&" => "&" + | _ => + if Char.isPrint ch orelse Char.isSpace ch then + str ch + else + "&#" ^ Int.toString (ord ch) ^ ";") + fun hexIt ch = let val s = Int.fmt StringCvt.HEX (ord ch) @@ -122,6 +132,13 @@ fun exp e = ESeq ((optExp (EWrite e1, loc), loc), (optExp (EWrite e2, loc), loc)) + | EFfiApp ("Basis", "htmlifyString", [(EPrim (Prim.String s), _)]) => + EPrim (Prim.String (htmlifyString s)) + | EWrite (EFfiApp ("Basis", "htmlifyString", [(EPrim (Prim.String s), _)]), loc) => + EWrite (EPrim (Prim.String (htmlifyString s)), loc) + | EWrite (EFfiApp ("Basis", "htmlifyString", [e]), _) => + EFfiApp ("Basis", "htmlifyString_w", [e]) + | EFfiApp ("Basis", "attrifyInt", [(EPrim (Prim.Int n), _)]) => EPrim (Prim.String (attrifyInt n)) | EWrite (EFfiApp ("Basis", "attrifyInt", [(EPrim (Prim.Int n), _)]), loc) => -- cgit v1.2.3