Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions webkit_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,9 +513,12 @@ def issue_command(self, cmd, *args):
self._writeline(cmd)
self._writeline(str(len(args)))
for arg in args:
arg = str(arg)
if type(arg) != str and type(arg) != unicode:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function cannot handle unicode strings. Try the following:

str(u"canción")

arg = str(arg)
if type(arg) == unicode:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only unicode strings need to be encoded as utf-8 to be sent as bytes to webkit server

arg = arg.encode("utf-8")
self._writeline(str(len(arg)))
self._sock.sendall(arg.encode("utf-8"))
self._sock.sendall(arg)

return self._read_response()

Expand All @@ -537,5 +540,7 @@ def _read_message(self):
return self.buf.read(size).decode("utf-8")

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a problem if you encode twice. Try the following:

u"canción".encode('utf-8').encode('utf-8')

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Encoding twice can create errors:

u"canción".encode('utf-8').encode('utf-8')

def _writeline(self, line):
if type(line) == unicode:
line = line.encode("utf-8")
""" Writes a line to the underlying socket. """
self._sock.sendall(line.encode("utf-8") + b"\n")
self._sock.sendall(line + b"\n")