Skip to content

Commit

Permalink
Issue #6448: Do not convert to link an email address whose domain nam…
Browse files Browse the repository at this point in the history
…e does not contain a TLD.

By @kiamlaluno, @indigoxela, and @herbdool.

Port of Drupal #2016739 by richardbporter, larowlan, aalamaki, afox, wroxbox, mark_fullmer, mohit_aghera, ayushmishra206, rakesh.gectcr, NikolaAt, rteijeiro, tanubansal, amietpatial, jibran, alexpott, Wim Leers
  • Loading branch information
kiamlaluno authored and quicksketch committed Apr 22, 2024
1 parent 987c408 commit 3527662
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
9 changes: 7 additions & 2 deletions core/modules/filter/filter.module
Expand Up @@ -2237,9 +2237,14 @@ function _filter_url($text, $filter) {

// Prepare domain name pattern.
// The ICANN seems to be on track towards accepting more diverse top level
// domains, so this pattern has been "future-proofed" to allow for TLDs
// domains (TLDs), so this pattern has been "future-proofed" to allow for TLDs
// of length 2-64.
$domain = '(?:[A-Za-z0-9._+-]+\.)?[A-Za-z]{2,64}\b';

// Mail domains differ from the generic domain pattern; specifically, a .
// character must be present in the string that follows the @ character.
$email_domain = '(?:[\p{L}\p{M}\p{N}._+-]+\.)+[\p{L}\p{M}]{2,64}\b';

$ip = '(?:[0-9]{1,3}\.){3}[0-9]{1,3}';
$auth = '[a-zA-Z0-9:%_+*~#?&=.,/;-]+@';
$trail = '[a-zA-Z0-9:%_+*~#&\[\]=/;?!\.,-]*[a-zA-Z0-9:%_+*~#&\[\]=/;-]';
Expand All @@ -2256,7 +2261,7 @@ function _filter_url($text, $filter) {
$tasks['_filter_url_parse_full_links'] = $pattern;

// Match email addresses.
$url_pattern = "[A-Za-z0-9._+-]{1,254}@(?:$domain)";
$url_pattern = "[\p{L}\p{M}\p{N}._+-]{1,254}@(?:$email_domain)";
$pattern = "`($url_pattern)`";
$tasks['_filter_url_parse_email_links'] = $pattern;

Expand Down
4 changes: 3 additions & 1 deletion core/modules/filter/tests/filter.url-input.txt
Expand Up @@ -9,6 +9,7 @@ This is just a www.test.com. paragraph with person@test.com. some http://www.tes
http://www.test.com
www.test.com
person@test.com
person@test
<code>www.test.com</code>

What about tags that don't exist <x>like x say www.test.com</x>? And what about tag <pooh>beginning www.test.com with p?</pooh>
Expand All @@ -25,12 +26,13 @@ The old URL filter has problems with <a title="kind of link www.example.com with
<dt>www.test.com</dt>
<dd>http://www.test.com</dd>
<dd>person@test.com</dd>
<dd>person@test</dd>
<dt>check www.test.com</dt>
<dd>this with some text around: http://www.test.com not so easy person@test.com now?</dd>
</dl>

<!-- <p>This url http://www.test.com is
inside a comment containing newlines and
inside a comment containing newlines and
<em>html</em> tags.</p> -->

This is the end!
4 changes: 3 additions & 1 deletion core/modules/filter/tests/filter.url-output.txt
Expand Up @@ -9,6 +9,7 @@ This is just a <a href="http://www.test.com">www.test.com</a>. paragraph with <a
<a href="http://www.test.com">http://www.test.com</a>
<a href="http://www.test.com">www.test.com</a>
<a href="mailto:person@test.com">person@test.com</a>
person@test
<code>www.test.com</code>

What about tags that don't exist <x>like x say <a href="http://www.test.com">www.test.com</a></x>? And what about tag <pooh>beginning <a href="http://www.test.com">www.test.com</a> with p?</pooh>
Expand All @@ -25,12 +26,13 @@ The old URL filter has problems with <a title="kind of link www.example.com with
<dt><a href="http://www.test.com">www.test.com</a></dt>
<dd><a href="http://www.test.com">http://www.test.com</a></dd>
<dd><a href="mailto:person@test.com">person@test.com</a></dd>
<dd>person@test</dd>
<dt>check <a href="http://www.test.com">www.test.com</a></dt>
<dd>this with some text around: <a href="http://www.test.com">http://www.test.com</a> not so easy <a href="mailto:person@test.com">person@test.com</a> now?</dd>
</dl>

<!-- <p>This url http://www.test.com is
inside a comment containing newlines and
inside a comment containing newlines and
<em>html</em> tags.</p> -->

This is the end!

0 comments on commit 3527662

Please sign in to comment.