Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE: Make it possible to validate host, source and target path #100

Open
wants to merge 3 commits into
base: 2.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to show all errors and not just the first one.
Will test it.

}

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>
markusguenther marked this conversation as resolved.
Show resolved Hide resolved
<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