Skip to content

Commit f0138c1

Browse files
committed
Merge branch 'release/3.2.28' into v3
2 parents 07cc4f6 + 38b25f6 commit f0138c1

File tree

63 files changed

+1877
-1914
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1877
-1914
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Retour Changelog
22

3+
## 3.2.28 - 2025.08.17
4+
### Changed
5+
* Use `StringHelper::convertToUtf8()` instead of our homebrew solution
6+
* Throw an exception if an attempt is made to edit a redirect that doesn't exist ([#345](https://github.com/nystudio107/craft-retour/issues/345))
7+
8+
### Fixed
9+
* Fixed a regression that caused the redirect loop detection to no longer function ([#348](https://github.com/nystudio107/craft-retour/issues/348))
10+
311
## 3.2.27 - 2025.06.13
412
### Changed
513
* Allow `RedirectEvent`s to change the redirect that is saved ([#342](https://github.com/nystudio107/craft-retour/issues/342))

buildchain/package-lock.json

Lines changed: 523 additions & 600 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "nystudio107/craft-retour",
33
"description": "Retour allows you to intelligently redirect legacy URLs, so that you don't lose SEO value when rebuilding & restructuring a website",
44
"type": "craft-plugin",
5-
"version": "3.2.27",
5+
"version": "3.2.28",
66
"keywords": [
77
"craftcms",
88
"craft-plugin",

docs/package-lock.json

Lines changed: 300 additions & 283 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/controllers/RedirectsController.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,7 @@ public function actionEditRedirect(
135135
if ($redirect === null) {
136136
$redirectConfig = Retour::$plugin->redirects->getRedirectById($redirectId);
137137
if ($redirectConfig === null) {
138-
$redirectConfig = [];
139-
Craft::error(
140-
Craft::t(
141-
'retour',
142-
"Couldn't load redirect id {id}",
143-
['id' => $redirectId]
144-
),
145-
__METHOD__
146-
);
138+
throw new NotFoundHttpException('Redirect not found');
147139
}
148140
$redirect = new StaticRedirectsModel($redirectConfig);
149141
}
@@ -279,7 +271,7 @@ public function actionSaveRedirect()
279271
}
280272
// Save the redirect
281273
$redirectConfig = $redirect->getAttributes();
282-
Retour::$plugin->redirects->saveRedirect($redirectConfig);
274+
Retour::$plugin->redirects->saveRedirect($redirectConfig, false);
283275
// Handle the case where the redirect wasn't saved because it'd create a redirect loop
284276
$testRedirectConfig = Retour::$plugin->redirects->getRedirectByRedirectSrcUrl(
285277
$redirectConfig['redirectSrcUrl'],

src/helpers/Text.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace nystudio107\retour\helpers;
1313

14+
use craft\helpers\StringHelper;
1415
use Stringy\Stringy;
1516

1617
/**
@@ -87,12 +88,7 @@ public static function cleanupText($text): string
8788
return '';
8889
}
8990
// Convert to UTF-8
90-
if (\function_exists('iconv')) {
91-
$text = iconv(mb_detect_encoding($text, mb_detect_order(), true), 'UTF-8//IGNORE', $text);
92-
} else {
93-
ini_set('mbstring.substitute_character', 'none');
94-
$text = mb_convert_encoding($text, 'UTF-8', 'UTF-8');
95-
}
91+
$text = StringHelper::convertToUtf8($text);
9692
// Strip HTML tags
9793
$text = strip_tags($text);
9894
// Remove excess whitespace

src/services/Redirects.php

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,9 +1086,10 @@ public function deleteShortlinkById(int $redirectId)
10861086

10871087
/**
10881088
* @param array $redirectConfig
1089-
* @return bool whether the redirect was saved or not
1089+
* @param bool $checkForRedirectLoop
1090+
* @return bool
10901091
*/
1091-
public function saveRedirect(array $redirectConfig): bool
1092+
public function saveRedirect(array $redirectConfig, bool $checkForRedirectLoop = true): bool
10921093
{
10931094
// Handle URL encoded URLs by decoding them before saving them
10941095
if (isset($redirectConfig['redirectMatchType']) && $redirectConfig['redirectMatchType'] === 'exactmatch') {
@@ -1201,6 +1202,32 @@ public function saveRedirect(array $redirectConfig): bool
12011202
return false;
12021203
}
12031204
}
1205+
if ($checkForRedirectLoop) {
1206+
// To prevent redirect loops, see if any static redirects have our redirectDestUrl as their redirectSrcUrl
1207+
$testRedirectConfig = $this->getRedirectByRedirectSrcUrl(
1208+
$redirectConfig['redirectDestUrl'],
1209+
$redirectConfig['siteId']
1210+
);
1211+
if ($testRedirectConfig !== null) {
1212+
Craft::debug(
1213+
Craft::t(
1214+
'retour',
1215+
'Deleting redirect to prevent a loop: {redirect}',
1216+
['redirect' => print_r($testRedirectConfig, true)]
1217+
),
1218+
__METHOD__
1219+
);
1220+
// Delete the redirect that has a redirectSrcUrl the same as this record's redirectDestUrl
1221+
try {
1222+
$db->createCommand()->delete(
1223+
'{{%retour_static_redirects}}',
1224+
['id' => $testRedirectConfig['id']]
1225+
)->execute();
1226+
} catch (Exception $e) {
1227+
Craft::error($e->getMessage(), __METHOD__);
1228+
}
1229+
}
1230+
}
12041231
// Trigger a 'afterSaveRedirect' event
12051232
$this->trigger(self::EVENT_AFTER_SAVE_REDIRECT, $event);
12061233

src/web/assets/dist/assets/dashboard-DVAYjtqJ.js

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
5.68 KB
Binary file not shown.

src/web/assets/dist/assets/dashboard-hn6fQang.js.map renamed to src/web/assets/dist/assets/dashboard-DVAYjtqJ.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)