From 8bcf1c59acf6206d04ebc11731afec821bd90b2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20M=C3=B6ller?= Date: Fri, 1 Nov 2024 11:38:18 +0100 Subject: [PATCH] fix: matching newline chars inside link tag I extended the mail display pattern to match link tag containing newline characters. --- Classes/Fusion/ConvertEmailLinksImplementation.php | 7 ++++--- .../Fusion/ConvertEmailLinksImplementationTest.php | 10 +++++++++- composer.json | 3 +++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Classes/Fusion/ConvertEmailLinksImplementation.php b/Classes/Fusion/ConvertEmailLinksImplementation.php index b7719fe..8af507c 100644 --- a/Classes/Fusion/ConvertEmailLinksImplementation.php +++ b/Classes/Fusion/ConvertEmailLinksImplementation.php @@ -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 ?? ''); } /** diff --git a/Tests/Unit/Fusion/ConvertEmailLinksImplementationTest.php b/Tests/Unit/Fusion/ConvertEmailLinksImplementationTest.php index 4c987dc..dcf6b28 100644 --- a/Tests/Unit/Fusion/ConvertEmailLinksImplementationTest.php +++ b/Tests/Unit/Fusion/ConvertEmailLinksImplementationTest.php @@ -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(); @@ -122,6 +122,14 @@ static public function emailTexts(): array 'email address in link tag enclosed by multiple styling tags' => [ 'Email test@example.com', 'Email test (at) example.com' + ], + 'email address in link tag enclosed by multiple styling tags and new line characters' => [ + 'Email + + test@example.com +', + 'Email + test (at) example.com' ] ]; } diff --git a/composer.json b/composer.json index 64432dc..252df7f 100644 --- a/composer.json +++ b/composer.json @@ -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"