File tree Expand file tree Collapse file tree 3 files changed +14
-2
lines changed
lib/ruby_lsp/ruby_lsp_rails Expand file tree Collapse file tree 3 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -281,7 +281,7 @@ def send_message(request, **params)
281
281
json = message . to_json
282
282
283
283
@mutex . synchronize do
284
- @stdin . write ( "Content-Length: #{ json . length } \r \n \r \n " , json )
284
+ @stdin . write ( "Content-Length: #{ json . bytesize } \r \n \r \n " , json )
285
285
end
286
286
rescue Errno ::EPIPE
287
287
# The server connection died
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ module Common
13
13
# Write a message to the client. Can be used for sending notifications to the editor
14
14
def send_message ( message )
15
15
json_message = message . to_json
16
- @stdout . write ( "Content-Length: #{ json_message . length } \r \n \r \n #{ json_message } " )
16
+ @stdout . write ( "Content-Length: #{ json_message . bytesize } \r \n \r \n #{ json_message } " )
17
17
end
18
18
19
19
# Log a message to the editor's output panel
Original file line number Diff line number Diff line change @@ -217,6 +217,18 @@ def resolve_route_info(requirements)
217
217
)
218
218
end
219
219
220
+ test "send_message uses bytesize for content length with ASCII characters" do
221
+ @server . send ( :send_message , { test : "hello" } )
222
+ assert_equal "Content-Length: 16\r \n \r \n {\" test\" :\" hello\" }" , @stdout . string
223
+ end
224
+
225
+ test "send_message uses bytesize for content length with multibyte characters" do
226
+ @server . send ( :send_message , { test : "こんにちは" } ) # Japanese "hello"
227
+ expected = "Content-Length: 26\r \n \r \n "
228
+ expected += { test : "こんにちは" } . to_json . force_encoding ( Encoding ::ASCII_8BIT )
229
+ assert_equal expected , @stdout . string
230
+ end
231
+
220
232
private
221
233
222
234
def response
You can’t perform that action at this time.
0 commit comments