[PATCH 10/16] remote-hg: improve email sanitation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Felipe Contreras <felipe.contreras@xxxxxxxxx>
---
 contrib/remote-helpers/git-remote-hg | 10 ++++++++--
 contrib/remote-helpers/test-hg.sh    |  8 ++++----
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/contrib/remote-helpers/git-remote-hg b/contrib/remote-helpers/git-remote-hg
index 3c6eeb7..0084709 100755
--- a/contrib/remote-helpers/git-remote-hg
+++ b/contrib/remote-helpers/git-remote-hg
@@ -51,6 +51,7 @@ import urlparse
 
 NAME_RE = re.compile('^([^<>]+)')
 AUTHOR_RE = re.compile('^([^<>]+?)? ?<([^<>]*)>$')
+EMAIL_RE = re.compile('^([^<>]+[^ \\\t<>])?\\b(?:[ \\t<>]*?)\\b([^ \\t<>]+@[^ \\t<>]+)')
 AUTHOR_HG_RE = re.compile('^(.*?) ?<(.*?)(?:>(.+)?)?$')
 RAW_AUTHOR_RE = re.compile('^(\w+) (?:(.+)? )?<(.*)> (\d+) ([+-]\d+)')
 
@@ -245,9 +246,14 @@ def fixup_user_git(user):
         name = m.group(1)
         mail = m.group(2).strip()
     else:
-        m = NAME_RE.match(user)
+        m = EMAIL_RE.match(user)
         if m:
-            name = m.group(1).strip()
+            name = m.group(1)
+            mail = m.group(2)
+        else:
+            m = NAME_RE.match(user)
+            if m:
+                name = m.group(1).strip()
     return (name, mail)
 
 def fixup_user_hg(user):
diff --git a/contrib/remote-helpers/test-hg.sh b/contrib/remote-helpers/test-hg.sh
index d5b8730..8de2aa7 100755
--- a/contrib/remote-helpers/test-hg.sh
+++ b/contrib/remote-helpers/test-hg.sh
@@ -137,15 +137,15 @@ test_expect_success 'authors' '
 
   author_test alpha "" "H G Wells <wells@xxxxxxxxxxx>" &&
   author_test beta "test" "test <unknown>" &&
-  author_test beta "test <test@xxxxxxxxxxx> (comment)" "test <unknown>" &&
+  author_test beta "test <test@xxxxxxxxxxx> (comment)" "test <test@xxxxxxxxxxx>" &&
   author_test gamma "<test@xxxxxxxxxxx>" "Unknown <test@xxxxxxxxxxx>" &&
   author_test delta "name<test@xxxxxxxxxxx>" "name <test@xxxxxxxxxxx>" &&
-  author_test epsilon "name <test@xxxxxxxxxxx" "name <unknown>" &&
+  author_test epsilon "name <test@xxxxxxxxxxx" "name <test@xxxxxxxxxxx>" &&
   author_test zeta " test " "test <unknown>" &&
   author_test eta "test < test@xxxxxxxxxxx >" "test <test@xxxxxxxxxxx>" &&
-  author_test theta "test >test@xxxxxxxxxxx>" "test <unknown>" &&
+  author_test theta "test >test@xxxxxxxxxxx>" "test <test@xxxxxxxxxxx>" &&
   author_test iota "test < test <at> example <dot> com>" "test <unknown>" &&
-  author_test kappa "test@xxxxxxxxxxx" "test@xxxxxxxxxxx <unknown>"
+  author_test kappa "test@xxxxxxxxxxx" "Unknown <test@xxxxxxxxxxx>"
   ) &&
 
   git clone "hg::$PWD/hgrepo" gitrepo &&
-- 
1.8.2.1.790.g4588561

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]