Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Commit

Permalink
Fix order of htmldecode/encode calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich Lott / Artful Robot committed Jun 11, 2020
1 parent 3be0772 commit a67bc25
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/ClickTracker/BaseClickTracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static function getTrackerURLForUrlWithTokens($url, $mailing_id, $queue_i

$trackable_url = $parsed[1];

// Proces the query parameters, if there are any.
// Process the query parameters, if there are any.
$tokenised_params = [];
$static_params = [];
if (!empty($parsed[2])) {
Expand Down
12 changes: 7 additions & 5 deletions src/ClickTracker/HtmlClickTracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ public function filterContent($msg, $mailing_id, $queue_id) {
return self::replaceHrefUrls($msg,
function ($url) use ($mailing_id, $queue_id, $getTrackerURL) {
if (strpos($url, '{') !== FALSE) {
$data = BaseClickTracker::getTrackerURLForUrlWithTokens($url, $mailing_id, $queue_id);
// If there are tokens in the URL use special treatment.

// Since we're dealing with HTML let's strip out the entities in the URL
// so that we can add them back in later.
$originalUrlDecoded = html_entity_decode($url);
$data = BaseClickTracker::getTrackerURLForUrlWithTokens($originalUrlDecoded, $mailing_id, $queue_id);
}
else {
$data = $getTrackerURL($url, $mailing_id, $queue_id);
Expand All @@ -42,9 +47,7 @@ function ($url) use ($mailing_id, $queue_id, $getTrackerURL) {
public static function replaceHrefUrls($html, $replace) {
$useNoFollow = TRUE;
$callback = function ($matches) use ($replace, $useNoFollow) {
// Since we're dealing with HTML let's strip out the entities in the URL
// so tht we can add them back in later.
$replacement = $replace(html_entity_decode($matches[2]));
$replacement = $replace($matches[2]);

// See: https://github.com/civicrm/civicrm-core/pull/12561
// If we track click-throughs on a link, then don't encourage search-engines to traverse them.
Expand All @@ -65,7 +68,6 @@ public static function replaceHrefUrls($html, $replace) {
';(\<[^>]*href *= *\')([^\'>]+)(\');', $callback, $tmp);
}


// /**
// * Find URL expressions; replace them with tracked URLs.
// *
Expand Down
2 changes: 1 addition & 1 deletion src/ClickTracker/TextClickTracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function filterContent($msg, $mailing_id, $queue_id) {
return self::replaceTextUrls($msg,
function ($url) use ($mailing_id, $queue_id, $getTrackerURL) {
if (strpos($url, '{') !== FALSE) {
$data = HtmlClickTracker::getTrackerURLForUrlWithTokens($url, $mailing_id, $queue_id);
$data = BaseClickTracker::getTrackerURLForUrlWithTokens($url, $mailing_id, $queue_id);
}
else {
$data = $getTrackerURL($url, $mailing_id, $queue_id);
Expand Down

0 comments on commit a67bc25

Please sign in to comment.