on master help sign in
Properly escape strings.
commit73f7d7cc9bdd742fb481d61abcaf8d20a0614c60 authorevancz <info@elm-lang.org> dateMon 3 Dec 2012, 22:21 (14 years ago) parent79d9d4c
1 file changed+7−1
elm/src/Gen/CompileToJS.hs+7−1
elm/src/Gen/CompileToJS.hs+7−1
@@ -26,13 +26,19 @@ indent = concatMap f
2626 f c = [c]
2727
2828parens s = "(" ++ s ++ ")"
29−quoted s = "'" ++ s ++ "'"
3029braces s = "{" ++ s ++ "}"
3130jsList ss = "["++ intercalate "," ss ++"]"
3231jsFunc args body = "function(" ++ args ++ "){" ++ indent body ++ "}"
3332assign x e = "\nvar " ++ x ++ "=" ++ e ++ ";"
3433ret e = "\nreturn "++ e ++";"
3534iff a b c = a ++ "?" ++ b ++ ":" ++ c
35+quoted s = "'" ++ concatMap f s ++ "'"
36+ where f '\n' = "\\n"
37+ f '\'' = "\\'"
38+ f '\t' = "\\t"
39+ f '\"' = "\\\""
40+ f '\\' = "\\\\"
41+ f c = [c]
3642
3743mainEquals s = globalAssign "Elm.main" (jsFunc "" (ret s))
3844globalAssign m s = "\n" ++ m ++ "=" ++ s ++ ";"