Skip to content

Commit

Permalink
Merge pull request #35 from networkteam/30-fix-mail-display
Browse files Browse the repository at this point in the history
fix: Mail obfuscation for links including additional tags
  • Loading branch information
ger4003 authored Oct 30, 2024
2 parents 1db9b90 + a8bb889 commit ad416cf
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Classes/Converter/Mailto2HrefObfuscatingConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function convert($mailAddress)
$randomOffset = random_int(1, 26);
}

return 'javascript:linkTo_UnCryptMailto(\'' . $this->encryptEmail($mailAddress, $randomOffset) . '\', -' . $randomOffset . ')';
return 'javascript:linkTo_UnCryptMailto(\'' . $this->encryptEmail($mailAddress, $randomOffset) . '\',-' . $randomOffset . ')';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Classes/Fusion/ConvertEmailLinksImplementation.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function convertLinkName(array $matches)
{
$replacedEmail = $this->linkNameConverter->convert(trim($matches[2]));

return $matches[1] . $replacedEmail;
return $matches[1] . $replacedEmail . $matches[3] ?? '';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Resources/Private/Fusion/Prototype/MailObfuscator.fusion
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ prototype(Networkteam.Neos:MailObfuscator) {
@class = 'Networkteam\\Neos\\MailObfuscator\\Fusion\\ConvertEmailLinksImplementation'

patternMailTo = '/(href=")mailto:([^"]*)/'
patternMailDisplay = '/(href="mailto:[^>]*>)([^<]*)/'
patternMailDisplay = '|(href="mailto:[^>]*>)(.*?)(<\/a>)|'

value = ${value}
node = ${node}
Expand Down
16 changes: 12 additions & 4 deletions Tests/Unit/Fusion/ConvertEmailLinksImplementationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,18 @@ public function emailsAreConverted($rawText, $expectedText)
->will($this->returnValueMap([
['value', $rawText],
['patternMailTo', '/(href=")mailto:([^"]*)/'],
['patternMailDisplay', '/(href="mailto:[^>]*>)([^<]*)/']
['patternMailDisplay', '|(href="mailto:[^>]*>)(.*?)(<\/a>)|']
]));

$actualResult = $this->convertEmailLinks->evaluate();
$this->assertSame($expectedText, $actualResult);
}

public function emailTexts(): array
static public function emailTexts(): array
{

$htmlEncodedDecryptionString = htmlspecialchars('javascript:linkTo_UnCryptMailto(\'ithiOtmpbeat-rdb\', -15)');
$htmlEncodedSecondDecryptionString = htmlspecialchars('javascript:linkTo_UnCryptMailto(\'uddqpgOtmpbeat-rdb\', -15)');
$htmlEncodedDecryptionString = htmlspecialchars('javascript:linkTo_UnCryptMailto(\'ithiOtmpbeat-rdb\',-15)', ENT_NOQUOTES);
$htmlEncodedSecondDecryptionString = htmlspecialchars('javascript:linkTo_UnCryptMailto(\'uddqpgOtmpbeat-rdb\',-15)', ENT_NOQUOTES);

return [
'just some text not to touch' => [
Expand All @@ -114,6 +114,14 @@ public function emailTexts(): array
'email address with attributes after href' => [
'Email <a href="mailto: [email protected]" itemprop="email">[email protected]</a>',
'Email <a href="' . $htmlEncodedDecryptionString . '" itemprop="email">test (at) example.com</a>'
],
'email address enclosed by HTML tag' => [
'Email <a href="mailto: [email protected]" itemprop="email"><strong>[email protected]</strong></a>',
'Email <a href="' . $htmlEncodedDecryptionString . '" itemprop="email"><strong>test (at) example.com</strong></a>'
],
'email address in link tag enclosed by multiple styling tags' => [
'Email <a href="mailto: [email protected]" itemprop="email"><i class="fa-light fa-paper-plane"></i><span class="btn__text">[email protected]</span></a>',
'Email <a href="' . $htmlEncodedDecryptionString . '" itemprop="email"><i class="fa-light fa-paper-plane"></i><span class="btn__text">test (at) example.com</span></a>'
]
];
}
Expand Down

0 comments on commit ad416cf

Please sign in to comment.