Skip to content

Commit

Permalink
Encode all text sent from the websocket-send-text function.
Browse files Browse the repository at this point in the history
This is necessary for non-ascii text.
  • Loading branch information
ahyatt committed Sep 3, 2012
1 parent 0efcdfe commit 29d8f2f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 7 additions & 0 deletions websocket-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,13 @@
(should-not on-open-calledp)
(should websocket-closed-calledp))))))

(ert-deftest websocket-send-text ()
(flet ((websocket-send (ws frame)
(should (equal
(websocket-frame-payload frame)
"\344\275\240\345\245\275"))))
(websocket-send-text nil "你好")))

(ert-deftest websocket-send ()
(let ((ws (websocket-inner-create :conn t :url t :accept-string t)))
(flet ((websocket-ensure-connected (websocket))
Expand Down
8 changes: 6 additions & 2 deletions websocket.el
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,12 @@ has connection termination."

(defun websocket-send-text (websocket text)
"To the WEBSOCKET, send TEXT as a complete frame."
(websocket-send websocket (make-websocket-frame :opcode 'text :payload text
:completep t)))
(websocket-send
websocket
(make-websocket-frame :opcode 'text
:payload (encode-coding-string
text 'raw-text)
:completep t)))

(defun websocket-check (frame)
"Check FRAME for correctness, returning true if correct."
Expand Down

0 comments on commit 29d8f2f

Please sign in to comment.