From 94efb43078f07020d75bd0fead804e468f3e972f Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Sat, 30 Mar 2019 15:17:27 +1100 Subject: [PATCH] dev/core#836 Do not track CSS urls when added as link urls --- CRM/Mailing/BAO/Mailing.php | 9 ++++++--- tests/phpunit/api/v3/MailingTest.php | 6 +++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CRM/Mailing/BAO/Mailing.php b/CRM/Mailing/BAO/Mailing.php index 927fdeec44..ce320a9b26 100644 --- a/CRM/Mailing/BAO/Mailing.php +++ b/CRM/Mailing/BAO/Mailing.php @@ -1367,9 +1367,12 @@ ORDER BY civicrm_email.is_bulkmail DESC } elseif ($type == 'url') { if ($this->url_tracking) { - $data = CRM_Mailing_BAO_TrackableURL::getTrackerURL($token, $this->id, $event_queue_id); - if (!empty($html)) { - $data = htmlentities($data, ENT_NOQUOTES); + // ensure that Google CSS and any .css files are not tracked. + if (!(strpos($token, 'css?family') || strpos($token, '.css'))) { + $data = CRM_Mailing_BAO_TrackableURL::getTrackerURL($token, $this->id, $event_queue_id); + if (!empty($html)) { + $data = htmlentities($data, ENT_NOQUOTES); + } } } else { diff --git a/tests/phpunit/api/v3/MailingTest.php b/tests/phpunit/api/v3/MailingTest.php index 5c7a16f941..f208df94b0 100644 --- a/tests/phpunit/api/v3/MailingTest.php +++ b/tests/phpunit/api/v3/MailingTest.php @@ -54,7 +54,7 @@ class api_v3_MailingTest extends CiviUnitTestCase { $this->_params = array( 'subject' => 'Hello {contact.display_name}', 'body_text' => "This is {contact.display_name}.\nhttps://civicrm.org\n{domain.address}{action.optOutUrl}", - 'body_html' => "

This is {contact.display_name}.

CiviCRM.org

{domain.address}{action.optOutUrl}

", + 'body_html' => "

This is {contact.display_name}.

CiviCRM.org

{domain.address}{action.optOutUrl}

", 'name' => 'mailing name', 'created_id' => $this->_contactID, 'header_id' => '', @@ -897,6 +897,10 @@ SELECT event_queue_id, time_stamp FROM mail_{$type}_temp"; $url = CRM_Mailing_Event_BAO_TrackableURLOpen::track($dao->queue_id, $dao->url_id); $this->assertContains('https://civicrm.org', $url); + + // Ensure that Google CSS link is not tracked. + $sql = "SELECT id FROM civicrm_mailing_trackable_url where url = 'https://fonts.googleapis.com/css?family=Roboto+Condensed:400,700|Zilla+Slab:500,700'"; + $this->assertEquals([], CRM_Core_DAO::executeQuery($sql)->fetchAll()); } /** -- 2.25.1