Skip to content

Commit 0e126c2

Browse files
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.
1 parent 62d0d71 commit 0e126c2

File tree

3 files changed

+36
-9
lines changed

3 files changed

+36
-9
lines changed

Classes/Controller/ModuleController.php

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -582,17 +582,30 @@ protected function deleteRedirect(string $sourceUriPath, ?string $host = null):
582582

583583
protected function validateRedirectAttributes(?string $host, string $sourceUriPath, string $targetUriPath): bool
584584
{
585+
$valid = true;
586+
585587
if ($sourceUriPath === $targetUriPath) {
586-
$this->addFlashMessage('', $this->translateById('error.sameSourceAndTarget'),
587-
Message::SEVERITY_WARNING);
588-
} elseif (!preg_match($this->validationOptions['sourceUriPath'], $sourceUriPath)) {
589-
$this->addFlashMessage('',
590-
$this->translateById('error.sourceUriPathNotValid', [$this->validationOptions['sourceUriPath']]),
591-
Message::SEVERITY_WARNING);
592-
} else {
593-
return true;
588+
$valid = false;
589+
$errorMessages[] = $this->translateById('error.sameSourceAndTarget');
590+
}
591+
if (isset($this->validationOptions['host']) && !preg_match($this->validationOptions['host'], $host)) {
592+
$valid = false;
593+
$errorMessages[] = $this->translateById('error.hostNotValid');
594+
}
595+
if (isset($this->validationOptions['sourceUriPath']) && !preg_match($this->validationOptions['sourceUriPath'], $sourceUriPath)) {
596+
$valid = false;
597+
$errorMessages[] = $this->translateById('error.sourceUriPathNotValid', [$this->validationOptions['sourceUriPath']]);
594598
}
595-
return false;
599+
if (isset($this->validationOptions['targetUriPath']) && !preg_match($this->validationOptions['targetUriPath'], $targetUriPath)) {
600+
$valid = false;
601+
$errorMessages[] = $this->translateById('error.targetUriPathNotValid', [$this->validationOptions['targetUriPath']]);
602+
}
603+
604+
if (!$valid) {
605+
$this->addFlashMessage('', implode('<br>', $errorMessages), Message::SEVERITY_WARNING);
606+
}
607+
608+
return $valid;
596609
}
597610

598611
protected function isSame(

Resources/Private/Translations/de/Modules.xlf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,14 @@
163163
<source>The source path doesn't match the expression {0}</source>
164164
<target>Der Quellpfad entspricht nicht dem Muster {0}</target>
165165
</trans-unit>
166+
<trans-unit id="error.targetUriPathNotValid" xml:space="preserve">
167+
<source>The target path doesn't match the expression {0}</source>
168+
<target>Der Zielpfad entspricht nicht dem Muster {0}</target>
169+
</trans-unit>
170+
<trans-unit id="error.hostNotValid" xml:space="preserve">
171+
<source>The host doesn't match the expression {0}</source>
172+
<target>Der Host entspricht nicht dem Muster {0}</target>
173+
</trans-unit>
166174
<trans-unit id="host" xml:space="preserve">
167175
<source>Origin domain</source>
168176
<target>Ursprungsdomäne</target>

Resources/Private/Translations/en/Modules.xlf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@
128128
<trans-unit id="error.sourceUriPathNotValid" xml:space="preserve">
129129
<source>The source path doesn't match the expression {0}</source>
130130
</trans-unit>
131+
<trans-unit id="error.targetUriPathNotValid" xml:space="preserve">
132+
<source>The target path doesn't match the expression {0}</source>
133+
</trans-unit>
134+
<trans-unit id="error.hostNotValid" xml:space="preserve">
135+
<source>The host doesn't match the expression {0}</source>
136+
</trans-unit>
131137

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

0 commit comments

Comments
 (0)