Skip to content

Commit

Permalink
Fix processing of multibyte messages
Browse files Browse the repository at this point in the history
* Too many characters are read from back-to-back multibyte messages due to a
conversion from byte-length to character length

* Updated to immediately convert messages to unibyte when processing
  • Loading branch information
weedjer committed Aug 1, 2024
1 parent 564b526 commit 4884740
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lsp-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -7041,8 +7041,8 @@ server. WORKSPACE is the active workspace."
leftovers body-length body chunk)
(lambda (_proc input)
(setf chunk (if (s-blank? leftovers)
input
(concat leftovers input)))
(encode-coding-string input 'utf-8-unix)
(concat leftovers (encode-coding-string input 'utf-8-unix))))

(let (messages)
(while (not (s-blank? chunk))
Expand Down
13 changes: 13 additions & 0 deletions test/lsp-io-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,19 @@
(messages (funcall fn message-in)))
(should (equal messages '("")))))

(ert-deftest lsp--parser-read--multiple-multibyte-messages ()
(let* ((fn (lsp--create-process-message))
(messages-in '("Content-Length: 3\r\n\r\n"
"Content-Length: 3\r\n\r\n"
"Content-Length:3\r\n\r\n"
"Content-Length: 3\r\n\r\n"
"Content-Length:3\r\n\r\n"
"Content-Length: 3\r\n\r\n"
"Content-Length: 3\r\n\r\n"
))
(messages (funcall fn (string-join messages-in))))
(should (equal messages '("" "" "" "" "" "" "")))))

(ert-deftest lsp--parser-read--multibyte-nospace ()
(let* ((fn (lsp--create-process-message))
(message-in "Content-Length:3\r\n\r\n\xe2\x80\x99")
Expand Down

0 comments on commit 4884740

Please sign in to comment.