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
This commit is contained in:
Robert Pluim 2023-02-15 12:16:11 +01:00
parent 8ee205d232
commit 03cfede8f0
2 changed files with 33 additions and 2 deletions

View file

@ -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.")

View file

@ -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