From a2e462c5b50c6072e478d434b3892c9f7155a084 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Mon, 22 Apr 2013 16:55:18 -0500 Subject: [PATCH] remote-hg: improve email sanitation Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- 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 3c6eeb7976..0084709c8c 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 d5b873051f..8de2aa7fec 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 " && author_test beta "test" "test " && - author_test beta "test (comment)" "test " && + author_test beta "test (comment)" "test " && author_test gamma "" "Unknown " && author_test delta "name" "name " && - author_test epsilon "name " && + author_test epsilon "name " && author_test zeta " test " "test " && author_test eta "test < test@example.com >" "test " && - author_test theta "test >test@example.com>" "test " && + author_test theta "test >test@example.com>" "test " && author_test iota "test < test example com>" "test " && - author_test kappa "test@example.com" "test@example.com " + author_test kappa "test@example.com" "Unknown " ) && git clone "hg::$PWD/hgrepo" gitrepo &&