Skip to content

Commit e4f3c9c

Browse files
shunyishunyi
authored andcommitted
Fix string length computation for issue_command function
When arg is not a ascii char, len(arg) may be differrent from len(arg.encode("utf-8")). For example, a Chinese character `c`, len(c) is 1, but len(c.encode("utf-8")) is 3, which will raise an InvalidResponseError because of the wrong length. This commit should fix this kind of problem.
1 parent 955577d commit e4f3c9c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

webkit_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ def issue_command(self, cmd, *args):
514514
self._writeline(str(len(args)))
515515
for arg in args:
516516
arg = str(arg)
517-
self._writeline(str(len(arg)))
517+
self._writeline(str(len(arg.encode("utf-8"))))
518518
self._sock.sendall(arg.encode("utf-8"))
519519

520520
return self._read_response()

0 commit comments

Comments
 (0)