Skip to content

Commit

Permalink
fix: Fixed an issue with impropertly text-encoded characters in URLs …
Browse files Browse the repository at this point in the history
…potentially causing a db exception ([#291](#291))
  • Loading branch information
khalwat committed Mar 6, 2024
1 parent bc307fc commit 0a53f11
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/services/Redirects.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use nystudio107\retour\events\RedirectResolvedEvent;
use nystudio107\retour\events\ResolveRedirectEvent;
use nystudio107\retour\fields\ShortLink;
use nystudio107\retour\helpers\Text as TextHelper;
use nystudio107\retour\helpers\UrlHelper;
use nystudio107\retour\models\StaticRedirects as StaticRedirectsModel;
use nystudio107\retour\Retour;
Expand Down Expand Up @@ -706,11 +707,11 @@ public function getStaticRedirect(string $fullUrl, string $pathOnly, $siteId, bo
'or',
['and',
['redirectSrcMatch' => 'pathonly'],
['redirectSrcUrlParsed' => $pathOnly],
['redirectSrcUrlParsed' => TextHelper::cleanupText($pathOnly)],
],
['and',
['redirectSrcMatch' => 'fullurl'],
['redirectSrcUrlParsed' => $fullUrl],
['redirectSrcUrlParsed' => TextHelper::cleanupText($fullUrl)],
],
];

Expand Down Expand Up @@ -860,7 +861,7 @@ public function getRedirectByRedirectSrcUrl(string $redirectSrcUrl, int $siteId
// Query the db table
$query = (new Query())
->from(['{{%retour_static_redirects}}'])
->where(['redirectSrcUrl' => $redirectSrcUrl]);
->where(['redirectSrcUrl' => TextHelper::cleanupText($redirectSrcUrl)]);
if ($siteId) {
$query
->andWhere(['or', [
Expand Down
6 changes: 4 additions & 2 deletions src/services/Statistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
use craft\db\Query;
use craft\helpers\Db;
use craft\helpers\UrlHelper;
use DateTime;
use nystudio107\retour\helpers\Text as TextHelper;
use nystudio107\retour\models\Stats as StatsModel;
use nystudio107\retour\Retour;
use yii\db\Exception;
Expand Down Expand Up @@ -193,7 +195,7 @@ public function incrementStatistics(string $url, $handled = false, $siteId = nul
// Find any existing retour_stats record
$statsConfig = (new Query())
->from(['{{%retour_stats}}'])
->where(['redirectSrcUrl' => $stats->redirectSrcUrl])
->where(['redirectSrcUrl' => TextHelper::cleanupText($stats->redirectSrcUrl)])
->one();
// If no record is found, initialize some values
if ($statsConfig === null) {
Expand All @@ -211,7 +213,7 @@ public function incrementStatistics(string $url, $handled = false, $siteId = nul
$stats->exceptionMessage = $exceptionMessage;
$stats->exceptionFilePath = $exceptionFilePath;
$stats->exceptionFileLine = (int)$exceptionFileLine;
$stats->hitLastTime = Db::prepareDateForDb(new \DateTime());
$stats->hitLastTime = Db::prepareDateForDb(new DateTime());
$stats->handledByRetour = (int)$handled;
$stats->hitCount++;
$statsConfig = $stats->getAttributes();
Expand Down

0 comments on commit 0a53f11

Please sign in to comment.