Skip to content

Commit

Permalink
Fix processing of multibyte messages (#4519)
Browse files Browse the repository at this point in the history
* Fix processing of multibyte messages

* 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

* Update encoding logic to avoid copies

---------

Co-authored-by: weedjer <[email protected]>
  • Loading branch information
JeremyWeed and weedjer authored Nov 10, 2024
1 parent 2f72a48 commit a49b386
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 @@ -7074,8 +7074,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 t)
(concat leftovers (encode-coding-string input 'utf-8-unix t))))

(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 a49b386

Please sign in to comment.