Need to escape #\' in javascript strings
authorMarco Baringer <mb@bese.it>
Wed, 5 Oct 2005 09:09:42 +0000 (09:09 +0000)
committerMarco Baringer <mb@bese.it>
Wed, 5 Oct 2005 09:09:42 +0000 (09:09 +0000)
js.lisp

diff --git a/js.lisp b/js.lisp
index e12be54..2fb039c 100644 (file)
--- a/js.lisp
+++ b/js.lisp
@@ -383,7 +383,15 @@ this macro."
 
 (defmethod js-to-strings ((string string-literal) start-pos)
   (declare (ignore start-pos))
-  (list (format nil "'~A'" (value string))))
+  (list (with-output-to-string (escaped)
+          (loop
+             initially (write-char #\' escaped)
+             for char across (value string)
+             if (char= #\' char)
+               do (write-string "\\'" escaped)
+             else
+               do (write-char char escaped)
+             finally (write-char #\' escaped)))))
 
 ;;; number literals