aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert Pluim2023-02-15 12:16:11 +0100
committerRobert Pluim2023-03-10 11:22:54 +0100
commit03cfede8f0aa952bde76fa595ca06770cc52e655 (patch)
tree00b4d4bd2b27efe93cb49a65e8ace0fff2a262f0
parent8ee205d232574e12921b052c7e93b7e16d6f1187 (diff)
downloademacs-03cfede8f0aa952bde76fa595ca06770cc52e655.tar.gz
emacs-03cfede8f0aa952bde76fa595ca06770cc52e655.zip
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
-rw-r--r--lisp/thingatpt.el2
-rw-r--r--test/lisp/thingatpt-tests.el33
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."
645 645
646;; Email addresses 646;; Email addresses
647(defvar thing-at-point-email-regexp 647(defvar thing-at-point-email-regexp
648 "<?[-+_.~a-zA-Z][-+_.~:a-zA-Z0-9]*@[-.a-zA-Z0-9]+>?" 648 "<?[-+_~a-zA-Z0-9][-+_.~:a-zA-Z0-9]*@[-a-zA-Z0-9]+[-.a-zA-Z0-9]*>?"
649 "A regular expression probably matching an email address. 649 "A regular expression probably matching an email address.
650This does not match the real name portion, only the address, optionally 650This does not match the real name portion, only the address, optionally
651with angle brackets.") 651with 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 @@
72 ("<url:ftp.example.net/abc/>" 1 url "ftp://ftp.example.net/abc/") 72 ("<url:ftp.example.net/abc/>" 1 url "ftp://ftp.example.net/abc/")
73 ;; UUID, only hex is allowed 73 ;; UUID, only hex is allowed
74 ("01234567-89ab-cdef-ABCD-EF0123456789" 1 uuid "01234567-89ab-cdef-ABCD-EF0123456789") 74 ("01234567-89ab-cdef-ABCD-EF0123456789" 1 uuid "01234567-89ab-cdef-ABCD-EF0123456789")
75 ("01234567-89ab-cdef-ABCD-EF012345678G" 1 uuid nil)) 75 ("01234567-89ab-cdef-ABCD-EF012345678G" 1 uuid nil)
76 ;; email addresses
77 ("foo@example.com" 1 email "foo@example.com")
78 ("f@example.com" 1 email "f@example.com")
79 ("foo@example.com" 4 email "foo@example.com")
80 ("foo@example.com" 5 email "foo@example.com")
81 ("foo@example.com" 15 email "foo@example.com")
82 ("foo@example.com" 16 email "foo@example.com")
83 ("<foo@example.com>" 1 email "<foo@example.com>")
84 ("<foo@example.com>" 4 email "<foo@example.com>")
85 ("<foo@example.com>" 5 email "<foo@example.com>")
86 ("<foo@example.com>" 16 email "<foo@example.com>")
87 ("<foo@example.com>" 17 email "<foo@example.com>")
88 ;; email adresses containing numbers
89 ("foo1@example.com" 1 email "foo1@example.com")
90 ("1foo@example.com" 1 email "1foo@example.com")
91 ("11@example.com" 1 email "11@example.com")
92 ("1@example.com" 1 email "1@example.com")
93 ;; email adresses user portion containing dots
94 ("foo.bar@example.com" 1 email "foo.bar@example.com")
95 (".foobar@example.com" 1 email nil)
96 (".foobar@example.com" 2 email "foobar@example.com")
97 ;; email adresses domain portion containing dots and dashes
98 ("foobar@.example.com" 1 email nil)
99 ("foobar@-example.com" 1 email "foobar@-example.com")
100 ;; These are illegal, but thingatpt doesn't yet handle them
101 ;; ("foo..bar@example.com" 1 email nil)
102 ;; ("foobar@.example.com" 1 email nil)
103 ;; ("foobar@example..com" 1 email nil)
104 ;; ("foobar.@example.com" 1 email nil)
105
106 )
76 "List of `thing-at-point' tests. 107 "List of `thing-at-point' tests.
77Each list element should have the form 108Each list element should have the form
78 109