summaryrefslogtreecommitdiff
path: root/src/mono_opt.sml
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adamc@hcoop.net>2008-07-17 13:33:56 -0400
committerGravatar Adam Chlipala <adamc@hcoop.net>2008-07-17 13:33:56 -0400
commit2e00cd0bdfadfab33a3c802994c8c0e5cf565174 (patch)
treee468f73f825fba86812b997da7f918a261ef30ef /src/mono_opt.sml
parent1676fa257dfb1f2569d6ffcdb1aea4c5a50dbae1 (diff)
Proper escaping of cdata
Diffstat (limited to 'src/mono_opt.sml')
-rw-r--r--src/mono_opt.sml17
1 files changed, 17 insertions, 0 deletions
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 #"\"" => "&quot;"
+ | #"&" => "&amp;"
| ch => if Char.isPrint ch then
str ch
else
@@ -54,6 +55,15 @@ val attrifyString = String.translate (fn #"\"" => "&quot;"
val urlifyInt = attrifyInt
val urlifyFloat = attrifyFloat
+val htmlifyString = String.translate (fn ch => case ch of
+ #"<" => "&lt;"
+ | #"&" => "&amp;"
+ | _ =>
+ 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) =>