branch: externals/websocket commit 37ef222d629a1da06a98530827cf0e9b456cd812 Author: Andrew Hyatt <ahy...@gmail.com> Commit: Andrew Hyatt <ahy...@gmail.com>
Stop converting the webmask to unibyte. Because we now set the string byte by byte, the string stays unibyte. I've tested this out and confirmed this. Besides the lack of need to run it, `unibyte-string' has been deprecated in Emacs, so we should stop using it. --- websocket.el | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/websocket.el b/websocket.el index b10bfb9dcd..8b318812ee 100644 --- a/websocket.el +++ b/websocket.el @@ -285,16 +285,13 @@ many bytes were consumed from the string." (defun websocket-mask (key data) "Using string KEY, mask string DATA according to the RFC. This is used to both mask and unmask data." - ;; If we don't make the string unibyte here, a string of bytes that should be - ;; interpreted as a unibyte string will instead be interpreted as a multibyte - ;; string of the same length (for example, 6 multibyte chars for 你好 instead - ;; of the correct 6 unibyte chars, which would convert into 2 multibyte - ;; chars). + ;; Returning the string as unibyte is important here. Because we set the + ;; string byte by byte, this results in a unibyte string. (cl-loop with result = (make-string (length data) ?x) for i from 0 below (length data) do (setf (seq-elt result i) (logxor (aref key (mod i 4)) (seq-elt data i))) - finally return (string-as-unibyte result))) + finally return result)) (defun websocket-ensure-length (s n) "Ensure the string S has at most N bytes.