git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Apr 22, 2013, 21:55 UTC
Message-ID
<1366667724-567-11-git-send-email-felipe.contreras@gmail.com>
In-Reply-To
<1366667724-567-1-git-send-email-felipe.contreras@gmail.com>
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 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@example.com>" &&
   author_test beta "test" "test <unknown>" &&
-  author_test beta "test <test@example.com> (comment)" "test <unknown>" &&
+  author_test beta "test <test@example.com> (comment)" "test <test@example.com>" &&
   author_test gamma "<test@example.com>" "Unknown <test@example.com>" &&
   author_test delta "name<test@example.com>" "name <test@example.com>" &&
-  author_test epsilon "name <test@example.com" "name <unknown>" &&
+  author_test epsilon "name <test@example.com" "name <test@example.com>" &&
   author_test zeta " test " "test <unknown>" &&
   author_test eta "test < test@example.com >" "test <test@example.com>" &&
-  author_test theta "test >test@example.com>" "test <unknown>" &&
+  author_test theta "test >test@example.com>" "test <test@example.com>" &&
   author_test iota "test < test <at> example <dot> com>" "test <unknown>" &&
-  author_test kappa "test@example.com" "test@example.com <unknown>"
+  author_test kappa "test@example.com" "Unknown <test@example.com>"
   ) &&
 
   git clone "hg::$PWD/hgrepo" gitrepo &&
-- 
1.8.2.1.790.g4588561
Previous: Felipe ContrerasNext: Felipe Contreras
Message 14 of 24 in “remote-hg: second round of improvements”
  1. 00/16 remote-hg: second round of improvementsFelipe Contreras, Apr 22, 2013
  2. 01/16 remote-helpers: avoid has_keyFelipe Contreras, Apr 22, 2013
  3. Junio C HamanoApr 22, 2013
  4. Felipe ContrerasApr 22, 2013
  5. Dusty PhillipsApr 22, 2013
  6. 02/16 remote-hg: safer bookmark pushingFelipe Contreras, Apr 22, 2013
  7. 03/16 remote-hg: use python urlparseFelipe Contreras, Apr 22, 2013
  8. 04/16 remote-hg: properly mark branches up-to-dateFelipe Contreras, Apr 22, 2013
  9. 05/16 remote-hg: add branch_tip() helperFelipe Contreras, Apr 22, 2013
  10. 06/16 remote-hg: add support for tag objectsFelipe Contreras, Apr 22, 2013
  11. 07/16 remote-hg: custom method to write tagsFelipe Contreras, Apr 22, 2013
  12. 08/16 remote-hg: write tags in the appropriate branchFelipe Contreras, Apr 22, 2013
  13. 09/16 remote-hg: add custom local tag write codeFelipe Contreras, Apr 22, 2013
  14. 10/16 remote-hg: improve email sanitationFelipe Contreras, Apr 22, 2013
  15. 11/16 remote-hg: add support for schemes extensionFelipe Contreras, Apr 22, 2013
  16. 12/16 remote-hg: don't update bookmarks unnecessarilyFelipe Contreras, Apr 22, 2013
  17. 13/16 remote-hg: allow refs with spacesFelipe Contreras, Apr 22, 2013
  18. Junio C HamanoApr 22, 2013
  19. Felipe ContrerasApr 22, 2013
  20. Junio C HamanoApr 22, 2013
  21. 14/16 remote-hg: small performance improvementFelipe Contreras, Apr 22, 2013
  22. 15/16 remote-hg: use marks instead of inlined filesFelipe Contreras, Apr 22, 2013
  23. Junio C HamanoApr 22, 2013
  24. 16/16 remote-hg: strip extra newlineFelipe Contreras, Apr 22, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.