Skip to content

Commit

Permalink
Capture email address with its local part being scheme string (#417)
Browse files Browse the repository at this point in the history
This patch fixes the parser so that it can capture an email address
whose local part matches a scheme string, e.g. 'http' or 'mailto'.

Fixes #414
  • Loading branch information
hanazuki authored Jan 3, 2023
1 parent 2246e4b commit ba048e0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/linkifyjs/src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ export function init({ groups }) {

tt(Localpart, tk.AT, LocalpartAt); // close to an email address now

// Local part of an email address can be e.g. 'http' or 'mailto'
tt(Scheme, tk.AT, LocalpartAt);
tt(SlashScheme, tk.AT, LocalpartAt);

const LocalpartDot = tt(Localpart, tk.DOT); // Local part of the email address plus '.' (localpart cannot end in .)
ta(LocalpartDot, localpartAccepting, Localpart);
ta(LocalpartDot, groups.domain, Localpart);
Expand Down
8 changes: 8 additions & 0 deletions test/spec/linkifyjs/parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,14 @@ const tests = [
'~emersion/[email protected]',
[Email],
['~emersion/[email protected]']
], [
'[email protected]',
[Email],
['[email protected]']
], [
'[email protected]',
[Email],
['[email protected]']
], [
'http.org',
[Url],
Expand Down

0 comments on commit ba048e0

Please sign in to comment.