Skip to content

Commit

Permalink
fix: Fixed an issue where an empty redirect in the excludePatterns
Browse files Browse the repository at this point in the history
…list could cause redirects to stop functioning, add logging when a redirect is excluded ([#297](#297))
  • Loading branch information
khalwat committed Mar 25, 2024
1 parent a032bf7 commit 35a27a3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/services/Redirects.php
Original file line number Diff line number Diff line change
Expand Up @@ -1210,9 +1210,21 @@ public function excludeUri($uri): bool
$uri = '/' . ltrim($uri, '/');
if (!empty(Retour::$settings->excludePatterns)) {
foreach (Retour::$settings->excludePatterns as $excludePattern) {
if (empty($excludePattern['pattern'])) {
continue;
}
$pattern = '`' . $excludePattern['pattern'] . '`i';
try {
if (preg_match($pattern, $uri) === 1) {
Craft::info(
Craft::t(
'retour',
'Excluded URI: {uri} due to match of pattern: {pattern}',
['uri' => $uri, 'pathOnly' => $pattern]
),
__METHOD__
);

return true;
}
} catch (\Exception $e) {
Expand Down
1 change: 1 addition & 0 deletions src/translations/en/retour.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,5 @@
'Some errors occured .' => 'Some errors occured .',
'Some errors occured importing the CSV file.' => 'Some errors occured importing the CSV file.',
'Select the priority that will determine the order of mathching the redirect.' => 'Select the priority that will determine the order of mathching the redirect.',
'Excluded URI: {uri} due to match of pattern: {pattern}' => 'Excluded URI: {uri} due to match of pattern: {pattern}'
];

0 comments on commit 35a27a3

Please sign in to comment.