Skip to content

Commit e3c3d38

Browse files
committed
fix: limit match length of email regular expression
closes #8
1 parent 65d8ac2 commit e3c3d38

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lib/index.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,22 @@ function transformGfmAutolinkLiterals(tree) {
141141
tree,
142142
[
143143
[/(https?:\/\/|www(?=\.))([-.\w]+)([^ \t\r\n]*)/gi, findUrl],
144-
[/([-.\w+]+)@([-\w]+(?:\.[-\w]+)+)/g, findEmail]
144+
// Use limited buffer sizes instead of `+` to avoid pathological regular
145+
// expression behavior; see
146+
// https://github.com/syntax-tree/mdast-util-gfm-autolink-literal/issues/8
147+
//
148+
// limits on email addresses:
149+
//
150+
// In addition to restrictions on syntax, there is a length limit on
151+
// email addresses. That limit is a maximum of 64 characters (octets)
152+
// in the "local part" (before the "@") and a maximum of 255 characters
153+
// (octets) in the domain part (after the "@") for a total length of 320
154+
// characters. However, there is a restriction in RFC 2821 on the length of an
155+
// address in MAIL and RCPT commands of 254 characters. Since addresses
156+
// that do not fit in those fields are not normally useful, the upper
157+
// limit on address lengths should normally be considered to be 254.
158+
// - http://www.rfc-editor.org/errata_search.php?rfc=3696&eid=1690
159+
[/([-.\w+]{1,64})@([-\w]{1,255}(?:\.[-\w]{1,255}){1,255})/g, findEmail]
145160
],
146161
{ignore: ['link', 'linkReference']}
147162
)

0 commit comments

Comments
 (0)