Skip to content

Commit

Permalink
Merge pull request #36 from networkteam/fix-matching-newline-charcter
Browse files Browse the repository at this point in the history
fix: matching newline chars inside link tag
  • Loading branch information
networkteam-lange authored Nov 1, 2024
2 parents 69b5937 + 8bcf1c5 commit ee036d9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
7 changes: 4 additions & 3 deletions Classes/Fusion/ConvertEmailLinksImplementation.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,10 @@ public function getValue()
*/
public function convertLinkName(array $matches)
{
$replacedEmail = $this->linkNameConverter->convert(trim($matches[2]));

return $matches[1] . $replacedEmail . ($matches[3] ?? '');
$lastMatch = array_pop($matches);
$linkNameMatch = trim($matches[2]);
$replacedEmail = $this->linkNameConverter->convert($linkNameMatch);
return $matches[1] . $replacedEmail . ($lastMatch ?? '');
}

/**
Expand Down
10 changes: 9 additions & 1 deletion Tests/Unit/Fusion/ConvertEmailLinksImplementationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function emailsAreConverted($rawText, $expectedText)
->will($this->returnValueMap([
['value', $rawText],
['patternMailTo', '/(href=")mailto:([^"]*)/'],
['patternMailDisplay', '|(href="mailto:[^>]*>)(.*?)(<\/a>)|']
['patternMailDisplay', '/(href="mailto:[^>]*>)((.|\n)*?)(<\/a>)/']
]));

$actualResult = $this->convertEmailLinks->evaluate();
Expand Down Expand Up @@ -122,6 +122,14 @@ static public function emailTexts(): array
'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>'
],
'email address in link tag enclosed by multiple styling tags and new line characters' => [
'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
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"neos/neos": "^3.0 || ^4.0 || ^5.0 || ^7.0 || ^8.0",
"guzzlehttp/guzzle": "*"
},
"require-dev": {
"phpunit/phpunit": "~9.1"
},
"autoload": {
"psr-4": {
"Networkteam\\Neos\\MailObfuscator\\": "Classes"
Expand Down

0 comments on commit ee036d9

Please sign in to comment.