diff --git a/xdebug/helper/helper.py b/xdebug/helper/helper.py index 8ded504..1e7a6c2 100644 --- a/xdebug/helper/helper.py +++ b/xdebug/helper/helper.py @@ -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) diff --git a/xdebug/view.py b/xdebug/view.py index 193295a..291c4d3 100644 --- a/xdebug/view.py +++ b/xdebug/view.py @@ -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