From 03cfede8f0aa952bde76fa595ca06770cc52e655 Mon Sep 17 00:00:00 2001 From: Robert Pluim Date: Wed, 15 Feb 2023 12:16:11 +0100 Subject: [PATCH] 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 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 @@ ("" 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") + ("" 1 email "") + ("" 4 email "") + ("" 5 email "") + ("" 16 email "") + ("" 17 email "") + ;; 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 -- 2.39.2