Skip to content
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

Add more email cloaking unit tests and fix email cloaking bug #13446

Merged
merged 1 commit into from
Jan 13, 2017
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions plugins/content/emailcloak/emailcloak.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,13 +377,13 @@ protected function _cloak(&$text, &$params)
while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE))
{
$mail = $regs[2][0] . $regs[3][0];
$mailText = $regs[4][0] . $regs[5][0] . $regs[6][0] . $regs[7][0];
$mailText = $regs[5][0] . $regs[6][0] . $regs[7][0];

// Check to see if mail text is different from mail addy
$replacement = JHtml::_('email.cloak', $mail, $mode, $mailText);

// Ensure that attributes is not stripped out by email cloaking
$replacement = html_entity_decode($this->_addAttributesToEmail($replacement, $regs[1][0], $regs[3][0]));
$replacement = html_entity_decode($this->_addAttributesToEmail($replacement, $regs[1][0], $regs[4][0]));

// Replace the found address with the js cloaked email
$text = substr_replace($text, $replacement, $regs[0][1], strlen($regs[0][0]));
Expand All @@ -398,12 +398,12 @@ protected function _cloak(&$text, &$params)
while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE))
{
$mail = $regs[2][0] . $regs[3][0];
$mailText = $regs[4][0] . $regs[5][0] . addslashes($regs[6][0]) . $regs[7][0];
$mailText = $regs[5][0] . addslashes($regs[6][0]) . $regs[7][0];

$replacement = JHtml::_('email.cloak', $mail, $mode, $mailText, 0);

// Ensure that attributes is not stripped out by email cloaking
$replacement = html_entity_decode($this->_addAttributesToEmail($replacement, $regs[1][0], $regs[3][0]));
$replacement = html_entity_decode($this->_addAttributesToEmail($replacement, $regs[1][0], $regs[4][0]));

// Replace the found address with the js cloaked email
$text = substr_replace($text, $replacement, $regs[0][1], strlen($regs[0][0]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ public function setup()
public function dataTestOnContentPrepare()
{
return array(

# 0
// 0
array(
// This first row is the input, this is what would be in the article
'this should not be parsed as it has no (at) sign in it - see what I did there? ;)',
Expand All @@ -90,28 +89,22 @@ public function dataTestOnContentPrepare()

),

# ? - see: https://github.com/joomla/joomla-cms/pull/11378#issuecomment-237829598
/**
* This is failing at the moment so Im excluding it while the above PR #11378 is worked on
* and while this unit test suite is being improved - but this test highlights the fact we need these tests!
*
* array(
* '<a href="mailto:[email protected]?subject=Mysubject" class="myclass" >email</a>',
* "<a href='mailto:[email protected]?subject=Mysubject' class='myclass' >email</a>",
* "
* <span id=\"cloak__HASH__\">JLIB_HTML_CLOAKING</span><script type='text/javascript'>
* document.getElementById('cloak__HASH__').innerHTML = '';
* var prefix = '&#109;a' + 'i&#108;' + '&#116;o';
* var path = 'hr' + 'ef' + '=';
* var addy__HASH__ = 't&#111;t&#111;' + '&#64;';
* addy__HASH__ = addy__HASH__ + 't&#111;t&#111;' + '&#46;' + 'c&#111;m?s&#117;bj&#101;ct=Mys&#117;bj&#101;ct';
* var addy_text__HASH__ = '&#101;m&#97;&#105;l';document.getElementById('cloak__HASH__').innerHTML += '<a ' + path + '\'' + prefix + ':' + addy__HASH__ + '\' class=\"myclass\" >'+addy_text__HASH__+'<\/a>';
* </script>
* "
* ),*/


# 1
// 1
array(
'<a href="mailto:[email protected]?subject=Mysubject" class="myclass" >email</a>',
"<a href='mailto:[email protected]?subject=Mysubject' class=\"myclass\" >email</a>",
"<span id=\"cloak__HASH__\">JLIB_HTML_CLOAKING</span><script type='text/javascript'>
document.getElementById('cloak__HASH__').innerHTML = '';
var prefix = '&#109;a' + 'i&#108;' + '&#116;o';
var path = 'hr' + 'ef' + '=';
var addy__HASH__ = 't&#111;t&#111;' + '&#64;';
addy__HASH__ = addy__HASH__ + 't&#111;t&#111;' + '&#46;' + 'c&#111;m?s&#117;bj&#101;ct=Mys&#117;bj&#101;ct';
var addy_text__HASH__ = '&#101;m&#97;&#105;l';document.getElementById('cloak__HASH__').innerHTML += '<a ' + path + '\'' + prefix + ':' + addy__HASH__ + '\' class=\"myclass\" >'+addy_text__HASH__+'<\/a>';
</script>
"
),

// 2
array(
'<a href="http://mce_host/ourdirectory/[email protected]">anytext</a>',

Expand All @@ -128,7 +121,7 @@ public function dataTestOnContentPrepare()
"
),

# 2
// 3
array(
'<p><a href="mailto:[email protected]"><span style="font-style: 8pt;">Joe_fontsize8</span></a></p>',

Expand All @@ -146,11 +139,11 @@ public function dataTestOnContentPrepare()
"
),

# 3
// 4
array(
'<p><a href="mailto:[email protected]?subject= A text"><span style="font-size: 14pt;">Joe_subject_ fontsize13</span></a></p>',

'<a href=\'mailto:[email protected]?subject= A text\'?subject= A text><span style="font-size: 14pt;">Joe_subject_ fontsize13</span></a>',
'<a href=\'mailto:[email protected]?subject= A text\'><span style="font-size: 14pt;">Joe_subject_ fontsize13</span></a>',

"
<p><span id=\"cloak__HASH__\">JLIB_HTML_CLOAKING</span><script type='text/javascript'>
Expand All @@ -159,56 +152,204 @@ public function dataTestOnContentPrepare()
var path = 'hr' + 'ef' + '=';
var addy__HASH__ = 'joe' + '@';
addy__HASH__ = addy__HASH__ + 'nowhere13' + '.' + 'com?subject= A text';
var addy_text__HASH__ = '<span style=\"font-size: 14pt;\">Joe_subject_ fontsize13</span>';document.getElementById('cloak__HASH__').innerHTML += '<a ' + path + '\'' + prefix + ':' + addy__HASH__ + '\'?subject= A text>'+addy_text__HASH__+'<\/a>';
var addy_text__HASH__ = '<span style=\"font-size: 14pt;\">Joe_subject_ fontsize13</span>';document.getElementById('cloak__HASH__').innerHTML += '<a ' + path + '\'' + prefix + ':' + addy__HASH__ + '\'>'+addy_text__HASH__+'<\/a>';
</script></p>
"
),

// 5
array(
'<p><a href="mailto:[email protected]"><strong>something</strong></a></p>',

// [
// '<p><a href="mailto:[email protected]"><span style="font-style: 14pt;">[email protected]</span></a></p>',
// '<span style="font-style: 8pt;">Joe_fontsize8</span>'
// ],
// [
// '<p><a href="mailto:[email protected]?subject= A text"><span style="font-size: 16pt;">[email protected]</span></a></p>',
// '<span style="font-style: 8pt;">Joe_fontsize8</span>'
// ],
// [
// '<p><a href="mailto:[email protected]"><strong>something</strong></a></p>',
// '<span style="font-style: 8pt;">Joe_fontsize8</span>'
// ],
// [
// '<p><a href="mailto:[email protected]"><strong>[email protected]</strong></a></p>',
// '<span style="font-style: 8pt;">Joe_fontsize8</span>'
// ],
// [
// '<p><a href="mailto:[email protected]?subject= A text"><strong><span style="font-size: 16px;">[email protected]</span></strong></a></p>',
// '<span style="font-style: 8pt;">Joe_fontsize8</span>'
// ],
// [
// '<p><a href="mailto:[email protected]"><strong><span style="font-size: 14px;">[email protected]</span></strong></a></p>',
// '<span style="font-style: 8pt;">Joe_fontsize8</span>'
// ],
// [
// '<p><a href="mailto:[email protected]"><strong><span style="font-size: 9px;">Joe Nobody</span></strong></a></p>',
// '<span style="font-style: 8pt;">Joe_fontsize8</span>'
// ],
// [
// '<p><a href="mailto:[email protected]"><strong><span>strong and span</span></strong></a></p>',
// '<span style="font-style: 8pt;">Joe_fontsize8</span>'
// ],
// [
// '<a href="mailto:[email protected]?subject=Text"><img src="path/to/something.jpg">[email protected]</img></a>',
// '<span style="font-style: 8pt;">Joe_fontsize8</span>'
// ],
// [
// '<a href="http://mce_host/ourdirectory/[email protected]">[email protected]</a>',
// '<a href="http://mce_host/ourdirectory/[email protected]">[email protected]</a>'
// ],
// [
// '<a href="mailto:[email protected]">[email protected]</a>',
// '<a href="mailto:[email protected]">[email protected]</a>'
// ],
'<a href=\'mailto:[email protected]\'><strong>something</strong></a>',

"
<p><span id=\"cloak__HASH__\">JLIB_HTML_CLOAKING</span><script type='text/javascript'>
document.getElementById('cloak__HASH__').innerHTML = '';
var prefix = 'ma' + 'il' + 'to';
var path = 'hr' + 'ef' + '=';
var addy__HASH__ = 'joe' + '@';
addy__HASH__ = addy__HASH__ + 'nowhere' + '.' + 'com';
var addy_text__HASH__ = '<strong>something</strong>';document.getElementById('cloak__HASH__').innerHTML += '<a ' + path + '\'' + prefix + ':' + addy__HASH__ + '\'>'+addy_text__HASH__+'<\/a>';
</script></p>
"
),

// 6
// TODO: I would expect that the email in the strong tag should ALSO be converted?
array(
'<p><a href="mailto:[email protected]"><strong>[email protected]</strong></a></p>',

'<a href=\'mailto:[email protected]\'><strong>[email protected]</strong></a>',

"
<p><span id=\"cloak__HASH__\">JLIB_HTML_CLOAKING</span><script type='text/javascript'>
document.getElementById('cloak__HASH__').innerHTML = '';
var prefix = 'ma' + 'il' + 'to';
var path = 'hr' + 'ef' + '=';
var addy__HASH__ = 'joe' + '@';
addy__HASH__ = addy__HASH__ + 'nowhere' + '.' + 'com';
var addy_text__HASH__ = '<strong>mymail' + '@' + 'mysite' + '.' + 'com</strong>';document.getElementById('cloak__HASH__').innerHTML += '<a ' + path + '\'' + prefix + ':' + addy__HASH__ + '\'>'+addy_text__HASH__+'<\/a>';
</script></p>
"
),

// 7
array(
'<p><a href="mailto:[email protected]"><strong><span style="font-size: 14px;">[email protected]</span></strong></a></p>',

'<a href=\'mailto:[email protected]\'><strong><span style="font-size: 14px;">[email protected]</span></strong></a>',

"
<p><span id=\"cloak__HASH__\">JLIB_HTML_CLOAKING</span><script type='text/javascript'>
document.getElementById('cloak__HASH__').innerHTML = '';
var prefix = 'ma' + 'il' + 'to';
var path = 'hr' + 'ef' + '=';
var addy__HASH__ = 'joe' + '@';
addy__HASH__ = addy__HASH__ + 'nowhere' + '.' + 'com';
var addy_text__HASH__ = '<strong><span style=\"font-size: 14px;\">mymail' + '@' + 'mysite' + '.' + 'com</span></strong>';document.getElementById('cloak__HASH__').innerHTML += '<a ' + path + '\'' + prefix + ':' + addy__HASH__ + '\'>'+addy_text__HASH__+'<\/a>';
</script></p>
"
),

// 8
array(
'<p><a href="mailto:[email protected]"><strong><span style="font-size: 14px;">Joe Nobody</span></strong></a></p>',

'<a href=\'mailto:[email protected]\'><strong><span style="font-size: 14px;">Joe Nobody</span></strong></a>',

"
<p><span id=\"cloak__HASH__\">JLIB_HTML_CLOAKING</span><script type='text/javascript'>
document.getElementById('cloak__HASH__').innerHTML = '';
var prefix = 'ma' + 'il' + 'to';
var path = 'hr' + 'ef' + '=';
var addy__HASH__ = 'joe' + '@';
addy__HASH__ = addy__HASH__ + 'nowhere' + '.' + 'com';
var addy_text__HASH__ = '<strong><span style=\"font-size: 14px;\">Joe Nobody</span></strong>';document.getElementById('cloak__HASH__').innerHTML += '<a ' + path + '\'' + prefix + ':' + addy__HASH__ + '\'>'+addy_text__HASH__+'<\/a>';
</script></p>
"
),

// 9
// TODO: I would expect that the email in the strong tag should ALSO be converted?
array(
'<p><a href="mailto:[email protected]?subject= A text"><strong><span style="font-size: 16px;">[email protected]</span></strong></a></p>',

'<a href=\'mailto:[email protected]?subject= A text\'><strong><span style="font-size: 16px;">[email protected]</span></strong></a>',

"
<p><span id=\"cloak__HASH__\">JLIB_HTML_CLOAKING</span><script type='text/javascript'>
document.getElementById('cloak__HASH__').innerHTML = '';
var prefix = 'ma' + 'il' + 'to';
var path = 'hr' + 'ef' + '=';
var addy__HASH__ = 'joe' + '@';
addy__HASH__ = addy__HASH__ + 'nowhere' + '.' + 'com?subject= A text';
var addy_text__HASH__ = '<strong><span style=\"font-size: 16px;\">joe' + '@' + 'nowhere' + '.' + 'com</span></strong>';document.getElementById('cloak__HASH__').innerHTML += '<a ' + path + '\'' + prefix + ':' + addy__HASH__ + '\'>'+addy_text__HASH__+'<\/a>';
</script></p>
"
),

// 10
array(
'<p><a href="mailto:[email protected]?subject=Text"><img src="path/to/something.jpg" />[email protected]</a></p>',

'<a href=\'mailto:[email protected]?subject=Text\'><img src="path/to/something.jpg" />[email protected]</a>',

"
<p><span id=\"cloak__HASH__\">JLIB_HTML_CLOAKING</span><script type='text/javascript'>
document.getElementById('cloak__HASH__').innerHTML = '';
var prefix = 'ma' + 'il' + 'to';
var path = 'hr' + 'ef' + '=';
var addy__HASH__ = 'joe' + '@';
addy__HASH__ = addy__HASH__ + 'nowhere' + '.' + 'com?subject=Text';
var addy_text__HASH__ = '<img src=\"path/to/something.jpg\" />joe' + '@' + 'nowhere' + '.' + 'com';document.getElementById('cloak__HASH__').innerHTML += '<a ' + path + '\'' + prefix + ':' + addy__HASH__ + '\'>'+addy_text__HASH__+'<\/a>';
</script></p>
"
),

// 11
array(
'<a href="http://mce_host/ourdirectory/[email protected]">[email protected]</a>',

"<a href='mailto:[email protected]'>[email protected]</a>",

"<span id=\"cloak__HASH__\">JLIB_HTML_CLOAKING</span><script type='text/javascript'>
document.getElementById('cloak__HASH__').innerHTML = '';
var prefix = '&#109;a' + 'i&#108;' + '&#116;o';
var path = 'hr' + 'ef' + '=';
var addy__HASH__ = '&#101;m&#97;&#105;l' + '&#64;';
addy__HASH__ = addy__HASH__ + '&#101;x&#97;mpl&#101;' + '&#46;' + '&#111;rg';
var addy_text__HASH__ = '&#101;m&#97;&#105;l' + '&#64;' + '&#101;x&#97;mpl&#101;' + '&#46;' + '&#111;rg';document.getElementById('cloak__HASH__').innerHTML += '<a ' + path + '\'' + prefix + ':' + addy__HASH__ + '\'>'+addy_text__HASH__+'<\/a>';
</script>
"
),

// 12 - similar to test 9 but with the addition of classes
// TODO: I would expect that the email in the strong tag should ALSO be converted?
array(
'<p><a href="mailto:[email protected]?subject= A text" class="class1 class2"><strong><span style="font-size: 16px;">[email protected]</span></strong></a></p>',

'<a href=\'mailto:[email protected]?subject= A text\' class="class1 class2"><strong><span style="font-size: 16px;">[email protected]</span></strong></a>',

"
<p><span id=\"cloak__HASH__\">JLIB_HTML_CLOAKING</span><script type='text/javascript'>
document.getElementById('cloak__HASH__').innerHTML = '';
var prefix = 'ma' + 'il' + 'to';
var path = 'hr' + 'ef' + '=';
var addy__HASH__ = 'joe' + '@';
addy__HASH__ = addy__HASH__ + 'nowhere' + '.' + 'com?subject= A text';
var addy_text__HASH__ = '<strong><span style=\"font-size: 16px;\">joe' + '@' + 'nowhere' + '.' + 'com</span></strong>';document.getElementById('cloak__HASH__').innerHTML += '<a ' + path + '\'' + prefix + ':' + addy__HASH__ + '\' class=\"class1 class2\">'+addy_text__HASH__+'<\/a>';
</script></p>
"
),

// 13 - Similar to test 4 but with the addition of classes
array(
'<p><a href="mailto:[email protected]?subject= A text" class="class 1 class 2"><span style="font-size: 14pt;">Joe_subject_ fontsize13</span></a></p>',

'<a href=\'mailto:[email protected]?subject= A text\' class="class 1 class 2"><span style="font-size: 14pt;">Joe_subject_ fontsize13</span></a>',

"
<p><span id=\"cloak__HASH__\">JLIB_HTML_CLOAKING</span><script type='text/javascript'>
document.getElementById('cloak__HASH__').innerHTML = '';
var prefix = 'ma' + 'il' + 'to';
var path = 'hr' + 'ef' + '=';
var addy__HASH__ = 'joe' + '@';
addy__HASH__ = addy__HASH__ + 'nowhere13' + '.' + 'com?subject= A text';
var addy_text__HASH__ = '<span style=\"font-size: 14pt;\">Joe_subject_ fontsize13</span>';document.getElementById('cloak__HASH__').innerHTML += '<a ' + path + '\'' + prefix + ':' + addy__HASH__ + '\' class=\"class 1 class 2\">'+addy_text__HASH__+'<\/a>';
</script></p>
"
),

// 14
array(
'<a href="mailto:[email protected]" class="myclass" >[email protected]</a>',
"<a href='mailto:[email protected]' class=\"myclass\" >[email protected]</a>",
"<span id=\"cloak__HASH__\">JLIB_HTML_CLOAKING</span><script type='text/javascript'>
document.getElementById('cloak__HASH__').innerHTML = '';
var prefix = '&#109;a' + 'i&#108;' + '&#116;o';
var path = 'hr' + 'ef' + '=';
var addy__HASH__ = 't&#111;t&#111;' + '&#64;';
addy__HASH__ = addy__HASH__ + 't&#111;t&#111;' + '&#46;' + 'c&#111;m';
var addy_text__HASH__ = 't&#111;t&#111;' + '&#64;' + 't&#111;t&#111;' + '&#46;' + 'c&#111;m';document.getElementById('cloak__HASH__').innerHTML += '<a ' + path + '\'' + prefix + ':' + addy__HASH__ + '\' class=\"myclass\" >'+addy_text__HASH__+'<\/a>';
</script>
"
),

// 15
array(
'<a href="mailto:[email protected]" class="myclass" >Click Here</a>',
"<a href='mailto:[email protected]' class=\"myclass\" >Click Here</a>",
"<span id=\"cloak__HASH__\">JLIB_HTML_CLOAKING</span><script type='text/javascript'>
document.getElementById('cloak__HASH__').innerHTML = '';
var prefix = '&#109;a' + 'i&#108;' + '&#116;o';
var path = 'hr' + 'ef' + '=';
var addy__HASH__ = 't&#111;t&#111;' + '&#64;';
addy__HASH__ = addy__HASH__ + 't&#111;t&#111;' + '&#46;' + 'c&#111;m';
var addy_text__HASH__ = 'Cl&#105;ck H&#101;r&#101;';document.getElementById('cloak__HASH__').innerHTML += '<a ' + path + '\'' + prefix + ':' + addy__HASH__ + '\' class=\"myclass\" >'+addy_text__HASH__+'<\/a>';
</script>
"
),
);
}

Expand Down