Skip to content

Commit ad416cf

Browse files
authored
Merge pull request #35 from networkteam/30-fix-mail-display
fix: Mail obfuscation for links including additional tags
2 parents 1db9b90 + a8bb889 commit ad416cf

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

Classes/Converter/Mailto2HrefObfuscatingConverter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function convert($mailAddress)
4444
$randomOffset = random_int(1, 26);
4545
}
4646

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

5050
/**

Classes/Fusion/ConvertEmailLinksImplementation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public function convertLinkName(array $matches)
109109
{
110110
$replacedEmail = $this->linkNameConverter->convert(trim($matches[2]));
111111

112-
return $matches[1] . $replacedEmail;
112+
return $matches[1] . $replacedEmail . $matches[3] ?? '';
113113
}
114114

115115
/**

Resources/Private/Fusion/Prototype/MailObfuscator.fusion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ prototype(Networkteam.Neos:MailObfuscator) {
1818
@class = 'Networkteam\\Neos\\MailObfuscator\\Fusion\\ConvertEmailLinksImplementation'
1919

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

2323
value = ${value}
2424
node = ${node}

Tests/Unit/Fusion/ConvertEmailLinksImplementationTest.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,18 @@ public function emailsAreConverted($rawText, $expectedText)
7777
->will($this->returnValueMap([
7878
['value', $rawText],
7979
['patternMailTo', '/(href=")mailto:([^"]*)/'],
80-
['patternMailDisplay', '/(href="mailto:[^>]*>)([^<]*)/']
80+
['patternMailDisplay', '|(href="mailto:[^>]*>)(.*?)(<\/a>)|']
8181
]));
8282

8383
$actualResult = $this->convertEmailLinks->evaluate();
8484
$this->assertSame($expectedText, $actualResult);
8585
}
8686

87-
public function emailTexts(): array
87+
static public function emailTexts(): array
8888
{
8989

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

9393
return [
9494
'just some text not to touch' => [
@@ -114,6 +114,14 @@ public function emailTexts(): array
114114
'email address with attributes after href' => [
115115
'Email <a href="mailto: [email protected]" itemprop="email">[email protected]</a>',
116116
'Email <a href="' . $htmlEncodedDecryptionString . '" itemprop="email">test (at) example.com</a>'
117+
],
118+
'email address enclosed by HTML tag' => [
119+
'Email <a href="mailto: [email protected]" itemprop="email"><strong>[email protected]</strong></a>',
120+
'Email <a href="' . $htmlEncodedDecryptionString . '" itemprop="email"><strong>test (at) example.com</strong></a>'
121+
],
122+
'email address in link tag enclosed by multiple styling tags' => [
123+
'Email <a href="mailto: [email protected]" itemprop="email"><i class="fa-light fa-paper-plane"></i><span class="btn__text">[email protected]</span></a>',
124+
'Email <a href="' . $htmlEncodedDecryptionString . '" itemprop="email"><i class="fa-light fa-paper-plane"></i><span class="btn__text">test (at) example.com</span></a>'
117125
]
118126
];
119127
}

0 commit comments

Comments
 (0)