From 05e9d45d27151d2228c0333cf043f128a1773f45 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Fri, 24 Sep 2021 16:04:26 +1000 Subject: [PATCH] [REF] CRM-19236 Fix Flexmailer extension to support unicode urls --- .../src/ClickTracker/HtmlClickTracker.php | 4 ++-- .../src/ClickTracker/TextClickTracker.php | 2 +- .../Civi/FlexMailer/ClickTrackerTest.php | 22 +++++++++++++++---- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/ext/flexmailer/src/ClickTracker/HtmlClickTracker.php b/ext/flexmailer/src/ClickTracker/HtmlClickTracker.php index adca06ed7e..9dd3759b37 100644 --- a/ext/flexmailer/src/ClickTracker/HtmlClickTracker.php +++ b/ext/flexmailer/src/ClickTracker/HtmlClickTracker.php @@ -51,9 +51,9 @@ class HtmlClickTracker implements ClickTrackerInterface { // Find anything like href="..." or href='...' inside a tag. $tmp = preg_replace_callback( - ';(\]*href *= *")([^">]+)(");i', $callback, $html); + ';(\]*href *= *")([^">]+)(");iu', $callback, $html); return preg_replace_callback( - ';(\]*href *= *\')([^\'>]+)(\');i', $callback, $tmp); + ';(\]*href *= *\')([^\'>]+)(\');iu', $callback, $tmp); } // /** diff --git a/ext/flexmailer/src/ClickTracker/TextClickTracker.php b/ext/flexmailer/src/ClickTracker/TextClickTracker.php index 31cdd90c2c..63a14a0955 100644 --- a/ext/flexmailer/src/ClickTracker/TextClickTracker.php +++ b/ext/flexmailer/src/ClickTracker/TextClickTracker.php @@ -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?):\/\/)[-A-Z0-9+&@#\/%=~_|$?!:,.{}\[\];]*[A-Z0-9+&@#\/%=~_|${}\[\];]/i', + return preg_replace_callback('/\b(?:(?:https?):\/\/)[\w+&@#\/%=~_|$?!:,.{}\[\];]*[\w+&@#\/%=~_|${}\[\];]/iu', $callback, $text); } diff --git a/ext/flexmailer/tests/phpunit/Civi/FlexMailer/ClickTrackerTest.php b/ext/flexmailer/tests/phpunit/Civi/FlexMailer/ClickTrackerTest.php index 91a7af91e2..5ba9c960e8 100644 --- a/ext/flexmailer/tests/phpunit/Civi/FlexMailer/ClickTrackerTest.php +++ b/ext/flexmailer/tests/phpunit/Civi/FlexMailer/ClickTrackerTest.php @@ -29,15 +29,15 @@ class ClickTrackerTest extends \PHPUnit\Framework\TestCase implements HeadlessIn // Mock the getTrackerURL call; we don't need to test creating a row in a table. // If you want this to work without runkit, then either (a) make the dummy rows or (b) switch this to a hook/event that is runtime-configurable. require_once 'CRM/Mailing/BAO/TrackableURL.php'; - runkit7_method_rename('\CRM_Mailing_BAO_TrackableURL', 'getBasicTrackerURL', 'orig_getBasicTrackerURL'); - runkit7_method_add('\CRM_Mailing_BAO_TrackableURL', 'getBasicTrackerURL', '$a, $b, $c', 'return \'http://example.com/extern?u=1&qid=1\';', RUNKIT7_ACC_STATIC | RUNKIT7_ACC_PRIVATE); + \runkit7_method_rename('\CRM_Mailing_BAO_TrackableURL', 'getBasicTrackerURL', 'orig_getBasicTrackerURL'); + \runkit7_method_add('\CRM_Mailing_BAO_TrackableURL', 'getBasicTrackerURL', '$a, $b, $c', 'return \'http://example.com/extern?u=1&qid=1\';', RUNKIT7_ACC_STATIC | RUNKIT7_ACC_PRIVATE); parent::setUp(); } public function tearDown(): void { // Reset the class. - runkit7_method_remove('\CRM_Mailing_BAO_TrackableURL', 'getBasicTrackerURL'); - runkit7_method_rename('\CRM_Mailing_BAO_TrackableURL', 'orig_getBasicTrackerURL', 'getBasicTrackerURL'); + \runkit7_method_remove('\CRM_Mailing_BAO_TrackableURL', 'getBasicTrackerURL'); + \runkit7_method_rename('\CRM_Mailing_BAO_TrackableURL', 'orig_getBasicTrackerURL', 'getBasicTrackerURL'); parent::tearDown(); } @@ -137,4 +137,18 @@ class ClickTrackerTest extends \PHPUnit\Framework\TestCase implements HeadlessIn $this->assertEquals('See this: https://example.com/{some.path}', $result); } + public function testLinkWithUnicode(): void { + $filter = new TextClickTracker(); + $msg = 'See this: https://civińcrm.org'; + $result = $filter->filterContent($msg, 1, 1); + $this->assertEquals('See this: http://example.com/extern?u=1&qid=1', $result); + } + + public function testHtmlLinkWithUnicode(): void { + $filter = new HtmlClickTracker(); + $msg = '

See This

'; + $result = $filter->filterContent($msg, 1, 1); + $this->assertEquals('

See This

', $result); + } + } -- 2.25.1