# HG changeset patch # User Mads Kiilerich # Date 1426029865 -3600 # Node ID 9ee018948dcd2d38e44a7a7d748c3c1ae5505526 # Parent d4b1b40b41ace4e0bd1b509cd6e4521950934a17 helpers: fix gravatar handling with (invalid) non-ascii email addresses It would crash with UnicodeDecodeError when trying to expand unicode email into utf8 template. diff -r d4b1b40b41ac -r 9ee018948dcd kallithea/lib/helpers.py --- a/kallithea/lib/helpers.py Wed Mar 11 00:24:25 2015 +0100 +++ b/kallithea/lib/helpers.py Wed Mar 11 00:24:25 2015 +0100 @@ -893,9 +893,6 @@ _gravatar_url = c.visual.gravatar_url or User.DEFAULT_GRAVATAR_URL email_address = email_address or _def - if isinstance(email_address, unicode): - #hashlib crashes on unicode items - email_address = safe_str(email_address) if not _use_gravatar or not email_address or email_address == _def: return "" @@ -906,7 +903,7 @@ tmpl = _gravatar_url parsed_url = urlparse.urlparse(url.current(qualified=True)) tmpl = tmpl.replace('{email}', email_address)\ - .replace('{md5email}', _md5(email_address.lower())) \ + .replace('{md5email}', _md5(safe_str(email_address).lower())) \ .replace('{netloc}', parsed_url.netloc)\ .replace('{scheme}', parsed_url.scheme)\ .replace('{size}', safe_str(size))