diff --git a/clog-connection.lisp b/clog-connection.lisp
index 6befa41..f1b4231 100644
--- a/clog-connection.lisp
+++ b/clog-connection.lisp
@@ -28,8 +28,9 @@
(validp function)
(cclose function)
(shutdown function)
- (cwrite function)
- (cwriteln function))
+ (put function)
+ (put-line function)
+ (new-line function))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -56,7 +57,9 @@
(let ((uid (clog::generate-connection-id)))
(clog::prep-query uid nil)
(execute connection-id
- (format nil "ws.send (\"~A:\"+eval(\"~A\"));" uid script))
+ (format nil "ws.send (\"~A:\"+eval(\"~A\"));"
+ uid
+ (clog:escape-string script)))
(clog::wait-for-answer uid)))
;;;;;;;;;;;;
@@ -87,18 +90,26 @@
reistablish connectivity."
(execute connection-id "Shutdown_ws(event.reason='user')"))
-;;;;;;;;;;;;
-;; cwrite ;;
-;;;;;;;;;;;;
+;;;;;;;;;
+;; put ;;
+;;;;;;;;;
-(defun cwrite (connection-id text)
- "Write TEXT raw to document object of CONNECTION-ID with out new line."
- (execute connection-id (format nil "document.write('~A');" text)))
+(defun put (connection-id text)
+ "Write TEXT to document object of CONNECTION-ID with out new line."
+ (execute connection-id (format nil "document.write('~A');" (clog:escape-string text))))
;;;;;;;;;;;;;;
-;; cwriteln ;;
+;; put-line ;;
;;;;;;;;;;;;;;
-(defun cwriteln (connection-id text)
- "Write TEXT raw to document object of CONNECTION-ID with new line."
- (execute connection-id (format nil "document.writeln('~A');" text)))
+(defun put-line (connection-id text)
+ "Write TEXT to document object of CONNECTION-ID with new line and HTML
."
+ (execute connection-id (format nil "document.writeln('~A
');" (clog:escape-string text))))
+
+;;;;;;;;;;;;;;
+;; new-line ;;
+;;;;;;;;;;;;;;
+
+(defun new-line (connection-id)
+ "Write a new line raw to document object of CONNECTION-ID with a
."
+ (execute connection-id (format nil "document.writeln('
');")))
diff --git a/clog.lisp b/clog.lisp
index 080f324..e9cb3ef 100644
--- a/clog.lisp
+++ b/clog.lisp
@@ -38,8 +38,9 @@ application."
(set-on-connect function)
"CLOG utilities"
-
- (open-browser function))
+
+ (escape-string function)
+ (open-browser function))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Implementation - clog
@@ -235,6 +236,19 @@ located at STATIC-ROOT."
"Change the ON-CONNECTION-HANDLER set during Initialize."
(setf *on-connect-handler* on-connect-handler))
+;;;;;;;;;;;;;;;;;;;
+;; escape-string ;;
+;;;;;;;;;;;;;;;;;;;
+
+(defun escape-string (str)
+ "Escape STR for sending to browser script."
+ (let ((res))
+ (setf res (ppcre:regex-replace-all "\\x22" str "\\x22"))
+ (setf res (ppcre:regex-replace-all "\\x27" res "\\x27"))
+ (setf res (ppcre:regex-replace-all "\\x0A" res "\\x0A"))
+ (setf res (ppcre:regex-replace-all "\\x0D" res "\\x0D"))
+ res))
+
;;;;;;;;;;;;;;;;;;
;; open-browser ;;
;;;;;;;;;;;;;;;;;;
diff --git a/test/test-clog.lisp b/test/test-clog.lisp
index b0ddb7f..da47655 100644
--- a/test/test-clog.lisp
+++ b/test/test-clog.lisp
@@ -7,17 +7,18 @@
(defun on-connect (id)
(format t "Connection ~A is valid? ~A~%" id (clog-connection:validp id))
(dotimes (n 10)
- (clog-connection:cwrite id "connection-write")
- (clog-connection:cwriteln id "connection-writeln")
+ (clog-connection:put id "connection-write")
+ (clog-connection:put-line id "connection-writeln")
(sleep .2))
- (clog-connection:cwrite id "
Query Result : ")
- (clog-connection:cwrite id (clog-connection:query id "navigator.appVersion"))
- (clog-connection:cwrite id "