allow hyphens in tracked URLs in text emails
authorlarssandergreen <lars@wildsight.ca>
Tue, 13 Dec 2022 02:36:48 +0000 (19:36 -0700)
committerlarssandergreen <lars@wildsight.ca>
Tue, 13 Dec 2022 02:36:48 +0000 (19:36 -0700)
ext/flexmailer/src/ClickTracker/TextClickTracker.php
ext/flexmailer/tests/phpunit/Civi/FlexMailer/ClickTracker/TextClickTrackerTest.php

index 63a14a0955e03dfdca05cbb25e9fa1f6caca0404..1fdea53e8b5a0f0edfa7a14822c2eb3ff4f4d9e3 100644 (file)
@@ -37,7 +37,7 @@ class TextClickTracker implements ClickTrackerInterface {
     };
     // Find any HTTP(S) URLs in the text.
     // return preg_replace_callback('/\b(?:(?:https?):\/\/|www\.|ftp\.)[-A-Z0-9+&@#\/%=~_|$?!:,.]*[A-Z0-9+&@#\/%=~_|$]/i', $callback, $tex
-    return preg_replace_callback('/\b(?:(?:https?):\/\/)[\w+&@#\/%=~_|$?!:,.{}\[\];]*[\w+&@#\/%=~_|${}\[\];]/iu',
+    return preg_replace_callback('/\b(?:(?:https?):\/\/)[\w+&@#\/%=~_|$?!:,.{}\[\];\-]*[\w+&@#\/%=~_|${}\[\];\-]/iu',
       $callback, $text);
   }
 
index db9653748549a778c274d4de8c3b4f0aadedefc9..14da23dd7889b8dcb229619bab8249a4da0fd3d0 100644 (file)
@@ -69,7 +69,11 @@ class TextClickTrackerTest extends \CiviUnitTestCase {
       '<p><a href="http://example.com/1">First</a><a href="http://example.com/2">Second</a><a href=\'http://example.com/3\'>Third</a><a href="http://example.com/4">Fourth</a></p>',
       '<p><a href="tracking(http://example.com/1)" rel=\'nofollow\'>First</a><a href="tracking(http://example.com/2)" rel=\'nofollow\'>Second</a><a href=\'tracking(http://example.com/3)\' rel=\'nofollow\'>Third</a><a href="tracking(http://example.com/4)" rel=\'nofollow\'>Fourth</a></p>',
     ];
-
+    $exs[] = [
+      // Messy looking URL, including hyphens
+      '<p><a href=\'https://sub.example-url.com/foo-bar.php?whiz=%2Fbang%2F&pie[fruit]=apple-pie\'>Foo</a></p>',
+      '<p><a href=\'tracking(https://sub.example-url.com/foo-bar.php?whiz=%2Fbang%2F&pie[fruit]=apple-pie)\' rel=\'nofollow\'>Foo</a></p>',
+    ];
     return $exs;
   }