Skip to content
Snippets Groups Projects
Commit b0183477 authored by ale's avatar ale
Browse files

Do not fail trying to decode list descriptions

There's all sorts of (undeclared) encodings in the list descriptions
we have in the databases, best if the API does not error out on them.
parent cde63073
No related branches found
No related tags found
No related merge requests found
......@@ -46,6 +46,19 @@ def _random_password():
return os.urandom(12).encode('base64').rstrip('=\n')
def _maybe_unicode(s):
# Try optimistically to guess the encoding of the list
# description (or just don't, nevermind).
try:
return unicode(s, 'utf-8')
except UnicodeEncodeError:
try:
return unicode(s, 'iso-8859-1')
except UnicodeEncodeError:
pass
return ''
@app.route('/api/create_list', methods=('POST',))
@tls_auth
@to_json
......@@ -89,7 +102,7 @@ def get_list_attrs():
attrs = {
'name': l,
'public': 'no' if m.archive_private else 'yes',
'description': unicode(m.description, 'utf-8'),
'description': _maybe_unicode(m.description),
'owners': list(set(m.owner[:])),
}
out.append(attrs)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment