Skip to content

fix: limit match length of email regular expression #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,22 @@ function transformGfmAutolinkLiterals(tree) {
tree,
[
[/(https?:\/\/|www(?=\.))([-.\w]+)([^ \t\r\n]*)/gi, findUrl],
[/([-.\w+]+)@([-\w]+(?:\.[-\w]+)+)/g, findEmail]
// Use limited buffer sizes instead of `+` to avoid pathological regular
// expression behavior; see
// https://github.com/syntax-tree/mdast-util-gfm-autolink-literal/issues/8
//
// limits on email addresses:
//
// In addition to restrictions on syntax, there is a length limit on
// email addresses. That limit is a maximum of 64 characters (octets)
// in the "local part" (before the "@") and a maximum of 255 characters
// (octets) in the domain part (after the "@") for a total length of 320
// characters. However, there is a restriction in RFC 2821 on the length of an
// address in MAIL and RCPT commands of 254 characters. Since addresses
// that do not fit in those fields are not normally useful, the upper
// limit on address lengths should normally be considered to be 254.
// - http://www.rfc-editor.org/errata_search.php?rfc=3696&eid=1690
[/([-.\w+]{1,64})@([-\w]{1,255}(?:\.[-\w]{1,255}){1,255})/g, findEmail]
],
{ignore: ['link', 'linkReference']}
)
Expand Down
Loading