From bec3032db481227a30b8a53958c4b23dc8dcbbca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Gu=CC=88nther?= Date: Wed, 9 Oct 2024 12:18:11 +0200 Subject: [PATCH] FEATURE: Make it possible to validate host, source and target path At the moment we can validate only the source path with a regex in the configuration. This change extends the function to be able to also validate the host and target path. --- Classes/Controller/ModuleController.php | 31 +++++++++++++------ Resources/Private/Translations/de/Modules.xlf | 8 +++++ Resources/Private/Translations/en/Modules.xlf | 6 ++++ 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/Classes/Controller/ModuleController.php b/Classes/Controller/ModuleController.php index a82b020..ccdcc7a 100644 --- a/Classes/Controller/ModuleController.php +++ b/Classes/Controller/ModuleController.php @@ -582,17 +582,30 @@ protected function deleteRedirect(string $sourceUriPath, ?string $host = null): protected function validateRedirectAttributes(?string $host, string $sourceUriPath, string $targetUriPath): bool { + $valid = true; + if ($sourceUriPath === $targetUriPath) { - $this->addFlashMessage('', $this->translateById('error.sameSourceAndTarget'), - Message::SEVERITY_WARNING); - } elseif (!preg_match($this->validationOptions['sourceUriPath'], $sourceUriPath)) { - $this->addFlashMessage('', - $this->translateById('error.sourceUriPathNotValid', [$this->validationOptions['sourceUriPath']]), - Message::SEVERITY_WARNING); - } else { - return true; + $valid = false; + $errorMessages[] = $this->translateById('error.sameSourceAndTarget'); + } + if (isset($this->validationOptions['host']) && !preg_match($this->validationOptions['host'], $host)) { + $valid = false; + $errorMessages[] = $this->translateById('error.hostNotValid'); + } + if (isset($this->validationOptions['sourceUriPath']) && !preg_match($this->validationOptions['sourceUriPath'], $sourceUriPath)) { + $valid = false; + $errorMessages[] = $this->translateById('error.sourceUriPathNotValid', [$this->validationOptions['sourceUriPath']]); } - return false; + if (isset($this->validationOptions['targetUriPath']) && !preg_match($this->validationOptions['targetUriPath'], $targetUriPath)) { + $valid = false; + $errorMessages[] = $this->translateById('error.targetUriPathNotValid', [$this->validationOptions['targetUriPath']]); + } + + if (!$valid) { + $this->addFlashMessage('', implode('
', $errorMessages), Message::SEVERITY_WARNING); + } + + return $valid; } protected function isSame( diff --git a/Resources/Private/Translations/de/Modules.xlf b/Resources/Private/Translations/de/Modules.xlf index 19b4eb6..9aaf07c 100644 --- a/Resources/Private/Translations/de/Modules.xlf +++ b/Resources/Private/Translations/de/Modules.xlf @@ -163,6 +163,14 @@ The source path doesn't match the expression {0} Der Quellpfad entspricht nicht dem Muster {0} + + The target path doesn't match the expression {0} + Der Zielpfad entspricht nicht dem Muster {0} + + + The host doesn't match the expression {0} + Der Host entspricht nicht dem Muster {0} + Origin domain Ursprungsdomäne diff --git a/Resources/Private/Translations/en/Modules.xlf b/Resources/Private/Translations/en/Modules.xlf index 300daed..32936d4 100644 --- a/Resources/Private/Translations/en/Modules.xlf +++ b/Resources/Private/Translations/en/Modules.xlf @@ -128,6 +128,12 @@ The source path doesn't match the expression {0} + + The target path doesn't match the expression {0} + + + The host doesn't match the expression {0} + Origin domain