Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapping ordered list and fix for special chars bug in array keys #205

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion xdebug/elementtree/ElementTree.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,8 @@ def _escape_cdata(text, encoding=None, replace=string.replace):
except UnicodeError:
return _encode_entity(text)
text = replace(text, "&", "&")
text = replace(text, "'", "'")
text = replace(text, "\"", """)
text = replace(text, "<", "&lt;")
text = replace(text, ">", "&gt;")
return text
Expand All @@ -818,7 +820,7 @@ def _escape_attrib(text, encoding=None, replace=string.replace):
except UnicodeError:
return _encode_entity(text)
text = replace(text, "&", "&amp;")
text = replace(text, "'", "&apos;") # FIXME: overkill
text = replace(text, "'", "&apos;")
text = replace(text, "\"", "&quot;")
text = replace(text, "<", "&lt;")
text = replace(text, ">", "&gt;")
Expand Down
8 changes: 4 additions & 4 deletions xdebug/helper/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,22 @@ def dictionary_values(dictionary):

def data_read(data):
# Convert bytes to string
return data.decode('utf8')
return data.decode('utf8', 'replace')


def data_write(data):
# Convert string to bytes
return bytes(data, 'utf8')
return bytes(data, 'utf8', 'replace')


def base64_decode(data):
# Base64 returns decoded byte string, decode to convert to UTF8 string
return base64.b64decode(data).decode('utf8')
return base64.b64decode(data).decode('utf8', 'replace')


def base64_encode(data):
# Base64 needs ascii input to encode, which returns Base64 byte string, decode to convert to UTF8 string
return base64.b64encode(data.encode('ascii')).decode('utf8')
return base64.b64encode(data.encode('ascii')).decode('utf8', 'replace')


def unicode_chr(code):
Expand Down
13 changes: 9 additions & 4 deletions xdebug/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,15 @@ def read_data(self):
# Verify length of response data
length = self.read_until_null()
message = self.read_until_null()
if int(length) == len(message):
return message
else:
raise ProtocolException('Length mismatch encountered while reading the Xdebug message')

return message

# Verification disabled due to incorrect length bug

# if int(length) == len(message):
# return message
# else:
# raise ProtocolException('Length mismatch encountered while reading the Xdebug message')

def read(self, return_string=False):
"""
Expand Down
36 changes: 20 additions & 16 deletions xdebug/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,27 @@ def get_real_path(uri, server=False):
if not drive_pattern.match(uri) and not os.path.isabs(uri):
uri = os.path.normpath('/' + uri)

mapped_paths = []
path_mapping = get_value(S.KEY_PATH_MAPPING)
if isinstance(path_mapping, dict):
# Go through path mappings
for server_path, local_path in path_mapping.items():
server_path = os.path.normpath(server_path)
local_path = os.path.normpath(local_path)
# Replace path if mapping available
if server:
# Map local path to server path
if local_path in uri:
uri = uri.replace(local_path, server_path)
break
else:
# Map server path to local path
if server_path in uri:
uri = uri.replace(server_path, local_path)
break
if isinstance(path_mapping, list):
mapped_paths.extend(path_mapping)
elif isinstance(path_mapping, dict):
mapped_paths.extend(path_mapping.items())
# Go through path mappings
for server_path, local_path in mapped_paths:
server_path = os.path.normpath(server_path)
local_path = os.path.normpath(local_path)
# Replace path if mapping available
if server:
# Map local path to server path
if local_path in uri:
uri = uri.replace(local_path, server_path)
break
else:
# Map server path to local path
if server_path in uri:
uri = uri.replace(server_path, local_path)
break
else:
sublime.set_timeout(lambda: sublime.status_message('Xdebug: No path mapping defined, returning given path.'), 100)

Expand Down