Skip to content

Commit 7db34da

Browse files
committed
avoid Illegal :UTF-8 character starting at position ... error
There are cases where typescript-language-server returns output that cannot be parsed as utf-8. ``` "sortText":"ï¿¿12\u0000msTextAutospace\u0000" ``` To avoid this problem, we will process the data as a byte string rather than a string.
1 parent 9690530 commit 7db34da

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/async-process.lisp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
(process :pointer)
6161
(string :string))
6262

63-
(cffi:defcfun ("process_receive_output" %process-receive-output) :string
63+
(cffi:defcfun ("process_receive_output" %process-receive-output) :pointer
6464
(process :pointer))
6565

6666
(cffi:defcfun ("process_alive_p" %process-alive-p) :boolean
@@ -93,9 +93,16 @@
9393
(let ((cffi:*default-foreign-encoding* (process-encode process)))
9494
(%process-send-input (process-process process) string)))
9595

96+
(defun pointer-to-string (pointer)
97+
(let ((bytes (loop :for i :from 0
98+
:for code := (cffi:mem-aref pointer :unsigned-char i)
99+
:until (zerop code)
100+
:collect code)))
101+
(map 'string 'code-char bytes)))
102+
96103
(defun process-receive-output (process)
97104
(let ((cffi:*default-foreign-encoding* (process-encode process)))
98-
(%process-receive-output (process-process process))))
105+
(pointer-to-string (%process-receive-output (process-process process)))))
99106

100107
(defun process-alive-p (process)
101108
(%process-alive-p (process-process process)))

0 commit comments

Comments
 (0)