changeset 39039:952bf3c948f0

mail: be more cautious about bytes vs str for py3 compat It's suboptimal that we get a bytes on 2 and a unicode on 3, but it's easy to work with and I'm disinclined to change anything unless we start using some sort of type inferencer. Differential Revision: https://phab.mercurial-scm.org/D4233
author Augie Fackler <augie@google.com>
date Thu, 09 Aug 2018 21:58:43 -0400
parents 2161faf0d24b
children f76c1343859d
files mercurial/mail.py
diffstat 1 files changed, 3 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/mail.py	Thu Aug 09 21:57:46 2018 -0400
+++ b/mercurial/mail.py	Thu Aug 09 21:58:43 2018 -0400
@@ -312,7 +312,9 @@
     try:
         acc, dom = addr.split(r'@')
         acc = acc.encode('ascii')
-        dom = dom.decode(encoding.encoding).encode('idna')
+        if isinstance(dom, bytes):
+            dom = dom.decode(encoding.encoding)
+        dom = dom.encode('idna')
         addr = '%s@%s' % (acc, dom)
     except UnicodeDecodeError:
         raise error.Abort(_('invalid email address: %s') % addr)