[shared] utils.py::normalizeString bugfix: when a string was not utf-8-encoded but latin-1-encoded, the method raised an exception.

This commit is contained in:
Gaetan Delannay 2014-08-27 09:53:45 +02:00
parent 2e1bdb9491
commit ac1d710288

View file

@ -218,7 +218,12 @@ def normalizeString(s, usage='fileName'):
'''
strNeeded = isinstance(s, str)
# We work in unicode. Convert p_s to unicode if not unicode.
if isinstance(s, str): s = s.decode('utf-8')
if isinstance(s, str):
try:
s = s.decode('utf-8')
except UnicodeDecodeError:
# Another encoding may be in use.
s = s.decode('latin-1')
elif not isinstance(s, unicode): s = unicode(s)
if usage == 'extractedText':
# Replace single quotes with blanks.