Skip to content

Commit

Permalink
FEATURE: Make it possible to validate host, source and target path
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
markusguenther committed Oct 9, 2024
1 parent 62d0d71 commit 0e126c2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
31 changes: 22 additions & 9 deletions Classes/Controller/ModuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('<br>', $errorMessages), Message::SEVERITY_WARNING);
}

return $valid;
}

protected function isSame(
Expand Down
8 changes: 8 additions & 0 deletions Resources/Private/Translations/de/Modules.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,14 @@
<source>The source path doesn't match the expression {0}</source>
<target>Der Quellpfad entspricht nicht dem Muster {0}</target>
</trans-unit>
<trans-unit id="error.targetUriPathNotValid" xml:space="preserve">
<source>The target path doesn't match the expression {0}</source>
<target>Der Zielpfad entspricht nicht dem Muster {0}</target>
</trans-unit>
<trans-unit id="error.hostNotValid" xml:space="preserve">
<source>The host doesn't match the expression {0}</source>
<target>Der Host entspricht nicht dem Muster {0}</target>
</trans-unit>
<trans-unit id="host" xml:space="preserve">
<source>Origin domain</source>
<target>Ursprungsdomäne</target>
Expand Down
6 changes: 6 additions & 0 deletions Resources/Private/Translations/en/Modules.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@
<trans-unit id="error.sourceUriPathNotValid" xml:space="preserve">
<source>The source path doesn't match the expression {0}</source>
</trans-unit>
<trans-unit id="error.targetUriPathNotValid" xml:space="preserve">
<source>The target path doesn't match the expression {0}</source>
</trans-unit>
<trans-unit id="error.hostNotValid" xml:space="preserve">
<source>The host doesn't match the expression {0}</source>
</trans-unit>

<trans-unit id="host" xml:space="preserve">
<source>Origin domain</source>
Expand Down

0 comments on commit 0e126c2

Please sign in to comment.