emacs-diffs
[Top][All Lists]
Advanced

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

master 03cfede8f0a: Improve thing-at-point email detection


From: Robert Pluim
Subject: master 03cfede8f0a: Improve thing-at-point email detection
Date: Fri, 10 Mar 2023 10:33:44 -0500 (EST)

branch: master
commit 03cfede8f0aa952bde76fa595ca06770cc52e655
Author: Robert Pluim <rpluim@gmail.com>
Commit: Robert Pluim <rpluim@gmail.com>

    Improve thing-at-point email detection
    
    * lisp/thingatpt.el (thing-at-point-email-regexp): Allow numbers at
    the start of the user portion, and disallow '.' at the start.  Also
    disallow '.' at the start of the domain portion.
    * test/lisp/thingatpt-tests.el (thing-at-point-test-data): Add various
    email tests.
    
    Bug#61519
---
 lisp/thingatpt.el            |  2 +-
 test/lisp/thingatpt-tests.el | 33 ++++++++++++++++++++++++++++++++-
 2 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/lisp/thingatpt.el b/lisp/thingatpt.el
index 9363a474cb5..f3367290dee 100644
--- a/lisp/thingatpt.el
+++ b/lisp/thingatpt.el
@@ -645,7 +645,7 @@ back from point."
 
 ;;   Email addresses
 (defvar thing-at-point-email-regexp
-  "<?[-+_.~a-zA-Z][-+_.~:a-zA-Z0-9]*@[-.a-zA-Z0-9]+>?"
+  "<?[-+_~a-zA-Z0-9][-+_.~:a-zA-Z0-9]*@[-a-zA-Z0-9]+[-.a-zA-Z0-9]*>?"
   "A regular expression probably matching an email address.
 This does not match the real name portion, only the address, optionally
 with angle brackets.")
diff --git a/test/lisp/thingatpt-tests.el b/test/lisp/thingatpt-tests.el
index 0daf27f32ec..7cf41d2817b 100644
--- a/test/lisp/thingatpt-tests.el
+++ b/test/lisp/thingatpt-tests.el
@@ -72,7 +72,38 @@
     ("<url:ftp.example.net/abc/>" 1 url "ftp://ftp.example.net/abc/";)
     ;; UUID, only hex is allowed
     ("01234567-89ab-cdef-ABCD-EF0123456789" 1 uuid 
"01234567-89ab-cdef-ABCD-EF0123456789")
-    ("01234567-89ab-cdef-ABCD-EF012345678G" 1 uuid nil))
+    ("01234567-89ab-cdef-ABCD-EF012345678G" 1 uuid nil)
+    ;; email addresses
+    ("foo@example.com" 1 email "foo@example.com")
+    ("f@example.com" 1 email "f@example.com")
+    ("foo@example.com" 4 email "foo@example.com")
+    ("foo@example.com" 5 email "foo@example.com")
+    ("foo@example.com" 15 email "foo@example.com")
+    ("foo@example.com" 16 email "foo@example.com")
+    ("<foo@example.com>" 1 email "<foo@example.com>")
+    ("<foo@example.com>" 4 email "<foo@example.com>")
+    ("<foo@example.com>" 5 email "<foo@example.com>")
+    ("<foo@example.com>" 16 email "<foo@example.com>")
+    ("<foo@example.com>" 17 email "<foo@example.com>")
+    ;; email adresses containing numbers
+    ("foo1@example.com" 1 email "foo1@example.com")
+    ("1foo@example.com" 1 email "1foo@example.com")
+    ("11@example.com" 1 email "11@example.com")
+    ("1@example.com" 1 email "1@example.com")
+    ;; email adresses user portion containing dots
+    ("foo.bar@example.com" 1 email "foo.bar@example.com")
+    (".foobar@example.com" 1 email nil)
+    (".foobar@example.com" 2 email "foobar@example.com")
+    ;; email adresses domain portion containing dots and dashes
+    ("foobar@.example.com" 1 email nil)
+    ("foobar@-example.com" 1 email "foobar@-example.com")
+    ;; These are illegal, but thingatpt doesn't yet handle them
+    ;;    ("foo..bar@example.com" 1 email nil)
+    ;;    ("foobar@.example.com" 1 email nil)
+    ;;    ("foobar@example..com" 1 email nil)
+    ;;    ("foobar.@example.com" 1 email nil)
+
+    )
   "List of `thing-at-point' tests.
 Each list element should have the form
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]