Skip to content
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
10 changes: 5 additions & 5 deletions xdebug/helper/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ 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):
def base64_decode(data, charset, errorMode = 'strict'):
# Base64 returns decoded byte string, decode to convert to UTF8 string
return base64.b64decode(data).decode('utf8')
return base64.b64decode(data).decode(charset, errorMode)

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):
return chr(code)
Expand Down
20 changes: 19 additions & 1 deletion xdebug/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,29 @@ def get_response_properties(response, default_key=None):
property_value = child.text
# Try to decode property value when encoded with base64
if property_encoding is not None and property_encoding == 'base64':
view = sublime.active_window().active_view()
match = re.search(r'\((.*?)\)', view.encoding())
encoding_name = '';
if match:
encoding_name = match.group(1)
encoding_name = encoding_name.replace(' ', '-').lower()
decoded = False
try:
property_value = H.base64_decode(child.text)
property_value = H.base64_decode(child.text, 'utf8')
decoded = True
except:
pass

if (not encoding_name == '') and (not encoding_name == 'Undefined'):
try:
property_value = H.base64_decode(child.text, encoding_name)
decoded = True
except:
pass

if not decoded:
property_value = H.base64_decode(child.text, 'utf8', 'replace')

if property_name is not None and len(property_name) > 0:
property_key = property_name
# Ignore following properties
Expand Down