changeset 9715:f0e99a2eac76

patchbomb: fix handling of email addresses with Unicode domains (IDNA) dom.encode('idna') requires dom to be a Unicode string.
author Marti Raudsepp <marti@juffo.org>
date Thu, 05 Nov 2009 10:49:28 +0100
parents 2f1ab7f77ddc
children ea8c207a0f78
files mercurial/mail.py tests/test-patchbomb tests/test-patchbomb.out
diffstat 3 files changed, 39 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/mail.py	Thu Nov 05 11:05:13 2009 +0100
+++ b/mercurial/mail.py	Thu Nov 05 10:49:28 2009 +0100
@@ -169,7 +169,7 @@
     try:
         acc, dom = addr.split('@')
         acc = acc.encode('ascii')
-        dom = dom.encode('idna')
+        dom = dom.decode(encoding.encoding).encode('idna')
         addr = '%s@%s' % (acc, dom)
     except UnicodeDecodeError:
         raise util.Abort(_('invalid email address: %s') % addr)
--- a/tests/test-patchbomb	Thu Nov 05 11:05:13 2009 +0100
+++ b/tests/test-patchbomb	Thu Nov 05 10:49:28 2009 +0100
@@ -170,3 +170,10 @@
 echo "% test multiple flags for multiple patches"
 hg email --date '1970-1-1 0:1' -n --flag fooFlag --flag barFlag -f quux -t foo \
  -c bar -s test -r 0:1 | fixheaders
+
+echo "% test multi-byte domain parsing"
+UUML=`echo -en '\xfc'`
+export HGENCODING=iso-8859-1
+hg email --date '1980-1-1 0:1' -m tmp.mbox -f quux -t "bar@${UUML}nicode.com" \
+  -s test -r 0
+cat tmp.mbox | fixheaders
--- a/tests/test-patchbomb.out	Thu Nov 05 11:05:13 2009 +0100
+++ b/tests/test-patchbomb.out	Thu Nov 05 10:49:28 2009 +0100
@@ -1469,3 +1469,34 @@
 @@ -0,0 +1,1 @@
 +b
 
+% test multi-byte domain parsing
+This patch series consists of 1 patches.
+
+
+Writing [PATCH] test ...
+From quux Tue Jan  1 00:01:01 1980
+Content-Type: text/plain; charset="us-ascii"
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+Subject: [PATCH] test
+X-Mercurial-Node: 8580ff50825a50c8f716709acdf8de0deddcd6ab
+Message-Id: <8580ff50825a50c8f716.315532860@
+User-Agent: Mercurial-patchbomb
+Date: Tue, 01 Jan 1980 00:01:00 +0000
+From: quux
+To: bar@xn--nicode-2ya.com
+
+# HG changeset patch
+# User test
+# Date 1 0
+# Node ID 8580ff50825a50c8f716709acdf8de0deddcd6ab
+# Parent  0000000000000000000000000000000000000000
+a
+
+diff -r 000000000000 -r 8580ff50825a a
+--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
++++ b/a	Thu Jan 01 00:00:01 1970 +0000
+@@ -0,0 +1,1 @@
++a
+
+