summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorTomás Touceda <chiiph@leap.se>2014-01-27 15:56:57 -0300
committerTomás Touceda <chiiph@leap.se>2014-01-27 15:56:57 -0300
commit5387c482921037a99e029fdd97f2c6a0d15d1093 (patch)
treeed209d240146a690a2ca1c289f1704e053c86d0a /client
parentf3d5cb68cc4cd15b6bfbd0f91b6d7036054381f6 (diff)
parent27a70fbbde42166c268c60e624ed11eac7788b55 (diff)
Merge remote-tracking branch 'refs/remotes/ivan/bug/always-return-unicode' into develop
Diffstat (limited to 'client')
-rw-r--r--client/changes/bug_return-always-unicode1
-rw-r--r--client/src/leap/soledad/client/__init__.py13
2 files changed, 8 insertions, 6 deletions
diff --git a/client/changes/bug_return-always-unicode b/client/changes/bug_return-always-unicode
new file mode 100644
index 00000000..f4ee51ed
--- /dev/null
+++ b/client/changes/bug_return-always-unicode
@@ -0,0 +1 @@
+ o Always return unicode in helper method, even on UnicodeError. Related to #4998.
diff --git a/client/src/leap/soledad/client/__init__.py b/client/src/leap/soledad/client/__init__.py
index 48c703ed..3fb037c8 100644
--- a/client/src/leap/soledad/client/__init__.py
+++ b/client/src/leap/soledad/client/__init__.py
@@ -859,7 +859,7 @@ class Soledad(object):
def _convert_to_unicode(self, content):
"""
- Converts content to utf8 (or all the strings in content)
+ Converts content to unicode (or all the strings in content)
NOTE: Even though this method supports any type, it will
currently ignore contents of lists, tuple or any other
@@ -874,13 +874,14 @@ class Soledad(object):
if isinstance(content, unicode):
return content
elif isinstance(content, str):
+ result = chardet.detect(content)
+ default = "utf-8"
+ encoding = result["encoding"] or default
try:
- result = chardet.detect(content)
- default = "utf-8"
- encoding = result["encoding"] or default
content = content.decode(encoding)
- except UnicodeError:
- pass
+ except UnicodeError as e:
+ logger.error("Unicode error: {0!r}. Using 'replace'".format(e))
+ content = content.decode(encoding, 'replace')
return content
else:
if isinstance(content, dict):