From 7555d45f9ad4ecdd578ffedf3cbc4b01d3ae0135 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Fri, 24 Sep 2021 11:43:09 +0200 Subject: [PATCH] Fix email labels with final digits Related to micromark/micromark-extension-gfm-autolink-literal#7. Related to remarkjs/remark#862. Closes GH-5. Co-authored-by: Rich Trott --- index.js | 8 +++- test/email-tld-digits.html | 39 +++++++++++++++++++ test/email-tld-digits.md | 77 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 122 insertions(+), 2 deletions(-) create mode 100644 test/email-tld-digits.html create mode 100644 test/email-tld-digits.md diff --git a/index.js b/index.js index 281e6c6..d3f006c 100644 --- a/index.js +++ b/index.js @@ -153,8 +153,12 @@ function findUrl(_, protocol, domain, path, match) { * @param {RegExpMatchObject} match */ function findEmail(_, atext, label, match) { - // Not an expected previous character. - if (!previous(match, true) || /[_-]$/.test(label)) { + if ( + // Not an expected previous character. + !previous(match, true) || + // Label ends in not allowed character. + /[_-\d]$/.test(label) + ) { return false } diff --git a/test/email-tld-digits.html b/test/email-tld-digits.html new file mode 100644 index 0000000..a8d1b61 --- /dev/null +++ b/test/email-tld-digits.html @@ -0,0 +1,39 @@ +

a@0.0

+

a@0.b

+

a@a.29

+

a@a.b

+

a@0.0.c

+

react@0.11.1

+

react@0.12.0-rc1

+

react@0.14.0-alpha1

+

react@16.7.0-alpha.2

+

react@0.0.0-experimental-aae83a4b9

+

[ react@0.11.1

+

[ react@0.12.0-rc1

+

[ react@0.14.0-alpha1

+

[ react@16.7.0-alpha.2

+

[ react@0.0.0-experimental-aae83a4b9

+
+

react@a

+

react@1

+

react@1.a

+

react@1.1

+

react@1.a-b

+

react@1.a1b

+

react@1.1-b

+

react@1.1-alpha

+

react@1.1-alpha1

+

react@1.1-a

+

react@1.a-1

+
+

[ react@a

+

[ react@1

+

[ react@1.a

+

[ react@1.1

+

[ react@1.a-b

+

[ react@1.a1b

+

[ react@1.1-b

+

[ react@1.1-alpha

+

[ react@1.1-alpha1

+

[ react@1.1-a

+

[ react@1.a-1

diff --git a/test/email-tld-digits.md b/test/email-tld-digits.md new file mode 100644 index 0000000..1dcda7a --- /dev/null +++ b/test/email-tld-digits.md @@ -0,0 +1,77 @@ +a@0.0 + +a@0.b + +a@a.29 + +a@a.b + +a@0.0.c + +react@0.11.1 + +react@0.12.0-rc1 + +react@0.14.0-alpha1 + +react@16.7.0-alpha.2 + +react@0.0.0-experimental-aae83a4b9 + +[ react@0.11.1 + +[ react@0.12.0-rc1 + +[ react@0.14.0-alpha1 + +[ react@16.7.0-alpha.2 + +[ react@0.0.0-experimental-aae83a4b9 + +--- + +react@a + +react@1 + +react@1.a + +react@1.1 + +react@1.a-b + +react@1.a1b + +react@1.1-b + +react@1.1-alpha + +react@1.1-alpha1 + +react@1.1-a + +react@1.a-1 + +--- + +[ react@a + +[ react@1 + +[ react@1.a + +[ react@1.1 + +[ react@1.a-b + +[ react@1.a1b + +[ react@1.1-b + +[ react@1.1-alpha + +[ react@1.1-alpha1 + +[ react@1.1-a + +[ react@1.a-1