Skip to content

Commit ee036d9

Browse files
Merge pull request #36 from networkteam/fix-matching-newline-charcter
fix: matching newline chars inside link tag
2 parents 69b5937 + 8bcf1c5 commit ee036d9

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

Classes/Fusion/ConvertEmailLinksImplementation.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,10 @@ public function getValue()
107107
*/
108108
public function convertLinkName(array $matches)
109109
{
110-
$replacedEmail = $this->linkNameConverter->convert(trim($matches[2]));
111-
112-
return $matches[1] . $replacedEmail . ($matches[3] ?? '');
110+
$lastMatch = array_pop($matches);
111+
$linkNameMatch = trim($matches[2]);
112+
$replacedEmail = $this->linkNameConverter->convert($linkNameMatch);
113+
return $matches[1] . $replacedEmail . ($lastMatch ?? '');
113114
}
114115

115116
/**

Tests/Unit/Fusion/ConvertEmailLinksImplementationTest.php

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

8383
$actualResult = $this->convertEmailLinks->evaluate();
@@ -122,6 +122,14 @@ static public function emailTexts(): array
122122
'email address in link tag enclosed by multiple styling tags' => [
123123
'Email <a href="mailto: [email protected]" itemprop="email"><i class="fa-light fa-paper-plane"></i><span class="btn__text">[email protected]</span></a>',
124124
'Email <a href="' . $htmlEncodedDecryptionString . '" itemprop="email"><i class="fa-light fa-paper-plane"></i><span class="btn__text">test (at) example.com</span></a>'
125+
],
126+
'email address in link tag enclosed by multiple styling tags and new line characters' => [
127+
'Email <a href="mailto: [email protected]" itemprop="email">
128+
<i class="fa-light fa-paper-plane"></i>
129+
<span class="btn__text">[email protected]</span>
130+
</a>',
131+
'Email <a href="' . $htmlEncodedDecryptionString . '" itemprop="email"><i class="fa-light fa-paper-plane"></i>
132+
<span class="btn__text">test (at) example.com</span></a>'
125133
]
126134
];
127135
}

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
"neos/neos": "^3.0 || ^4.0 || ^5.0 || ^7.0 || ^8.0",
88
"guzzlehttp/guzzle": "*"
99
},
10+
"require-dev": {
11+
"phpunit/phpunit": "~9.1"
12+
},
1013
"autoload": {
1114
"psr-4": {
1215
"Networkteam\\Neos\\MailObfuscator\\": "Classes"

0 commit comments

Comments
 (0)