Skip to content

Commit a49b386

Browse files
Fix processing of multibyte messages (#4519)
* 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]>
1 parent 2f72a48 commit a49b386

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

lsp-mode.el

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7074,8 +7074,8 @@ server. WORKSPACE is the active workspace."
70747074
leftovers body-length body chunk)
70757075
(lambda (_proc input)
70767076
(setf chunk (if (s-blank? leftovers)
7077-
input
7078-
(concat leftovers input)))
7077+
(encode-coding-string input 'utf-8-unix t)
7078+
(concat leftovers (encode-coding-string input 'utf-8-unix t))))
70797079

70807080
(let (messages)
70817081
(while (not (s-blank? chunk))

test/lsp-io-test.el

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,19 @@
6666
(messages (funcall fn message-in)))
6767
(should (equal messages '("")))))
6868

69+
(ert-deftest lsp--parser-read--multiple-multibyte-messages ()
70+
(let* ((fn (lsp--create-process-message))
71+
(messages-in '("Content-Length: 3\r\n\r\n"
72+
"Content-Length: 3\r\n\r\n"
73+
"Content-Length:3\r\n\r\n"
74+
"Content-Length: 3\r\n\r\n"
75+
"Content-Length:3\r\n\r\n"
76+
"Content-Length: 3\r\n\r\n"
77+
"Content-Length: 3\r\n\r\n"
78+
))
79+
(messages (funcall fn (string-join messages-in))))
80+
(should (equal messages '("" "" "" "" "" "" "")))))
81+
6982
(ert-deftest lsp--parser-read--multibyte-nospace ()
7083
(let* ((fn (lsp--create-process-message))
7184
(message-in "Content-Length:3\r\n\r\n\xe2\x80\x99")

0 commit comments

Comments
 (0)