bracey.vim icon indicating copy to clipboard operation
bracey.vim copied to clipboard

Fix to support sending strings containing multibyte characters.

Open gen4438 opened this issue 3 years ago • 2 comments

Fixed to work correctly even if the argument of bracey#sendCommand() contains multibyte characters.

gen4438 avatar May 05 '21 15:05 gen4438

Thank you for the comment! I found bracey and it seems to be very convenient for me, so I would like to use it.

An error occurred when I used Japanese for the path. For example, running bracey on the file /home/test_user/bracey_テスト/index.html will fail to start (テスト means test).

autoload/bracey.vim processes in byte length, while server/server.js processes in string length. And the path /home/test_user/bracey_テスト/index.html has 37 characters and 43 bytes. As a result, in server/server.js, the path is interpreted as /home/test_user/bracey_テスト/index.html:4:htm (additional 6 characters are read). This causes the following error:

starting bracey with arguments:
port: 60196
web-address: 127.0.0.1
editor-address: 127.0.0.1
/home/test_user/.vim/plugged/bracey.vim/server/server.js:87
	var commandArgs = [commandData];
	                  ^

RangeError: Maximum call stack size exceeded
    at Server.parseEditorRequest (/home/test_user/.vim/plugged/bracey.vim/server/server.js:87:20)
    at Server.parseEditorRequest (/home/test_user/.vim/plugged/bracey.vim/server/server.js:109:8)
    at Server.parseEditorRequest (/home/test_user/.vim/plugged/bracey.vim/server/server.js:109:8)
    at Server.parseEditorRequest (/home/test_user/.vim/plugged/bracey.vim/server/server.js:109:8)
    at Server.parseEditorRequest (/home/test_user/.vim/plugged/bracey.vim/server/server.js:109:8)
    at Server.parseEditorRequest (/home/test_user/.vim/plugged/bracey.vim/server/server.js:109:8)
    at Server.parseEditorRequest (/home/test_user/.vim/plugged/bracey.vim/server/server.js:109:8)
    at Server.parseEditorRequest (/home/test_user/.vim/plugged/bracey.vim/server/server.js:109:8)
    at Server.parseEditorRequest (/home/test_user/.vim/plugged/bracey.vim/server/server.js:109:8)
    at Server.parseEditorRequest (/home/test_user/.vim/plugged/bracey.vim/server/server.js:109:8)

Also, if the html includes multibyte characters, the length of the content will be interpreted incorrectly. (Even so, it shouldn't be a problem as the length of content is overestimated and the file will be read to the end.)

A html example with multibyte characters.

<!DOCTYPE html>
<html lang="ja">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <h1>Hello World!</h1>
    これは bracey のテストのための html ファイルです。
  </body>
</html>

gen4438 avatar May 13 '21 15:05 gen4438

Thanks for follow up with an example! Would love to get this fixed! :heart: :symbols:

My original comment still stands. since file paths on many operating systems are just bags of bytes I think it'd be best to fix this on the js side. The real issue is erroneously interpreting file paths into unicode strings.

Also since you have such a great example throwing some tests in there would be awesome!

turbio avatar May 13 '21 18:05 turbio