Skip to content

Commit

Permalink
Fix microsoft#1037: Setting breakpoint fails on Python files containi…
Browse files Browse the repository at this point in the history
…ng non-ASCII characters

Fix microsoft#1066: Fetching remote source for a file with a Unicode name fails on 2.7
  • Loading branch information
int19h committed Dec 6, 2018
1 parent fb5e7ac commit d298fc1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/ptvsd/pathutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Licensed under the MIT License. See LICENSE in the project root
# for license information.

from __future__ import print_function, with_statement, absolute_import
from __future__ import print_function, with_statement, absolute_import, unicode_literals

from glob import glob
import os.path
Expand Down
22 changes: 18 additions & 4 deletions src/ptvsd/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,21 @@ def __init__(self, cmdid):
self.cmdid = cmdid


def unquote(s):
if s is None:
return None
return urllib.unquote(s)
if sys.version_info >= (3,):
def unquote(s):
return None if s is None else urllib.unquote(s)
else:
# In Python 2, urllib.unquote doesn't handle Unicode strings correctly,
# so we need to convert to ASCII first, unquote, and then decode.
def unquote(s):
if s is None:
return None
if not isinstance(s, bytes):
s = bytes(s)
s = urllib.unquote(s)
if isinstance(s, bytes):
s = s.decode('utf-8')
return s


def unquote_xml_path(s):
Expand Down Expand Up @@ -1605,7 +1616,10 @@ def on_source(self, request, args):
if source_reference == 0:
self.send_error_response(request, 'Source unavailable')
else:
if sys.version_info < (3,) and not isinstance(filename, bytes):
filename = filename.encode(sys.getfilesystemencoding())
server_filename = path_to_unicode(pydevd_file_utils.norm_file_to_server(filename))

cmd = pydevd_comm.CMD_LOAD_SOURCE
_, _, content = yield self.pydevd_request(cmd, server_filename)
self.send_response(request, content=content)
Expand Down

0 comments on commit d298fc1

Please sign in to comment.