[BUGFIX] Catch possible error due to wrong redirect regex 17/59817/7
authorMarkus Klein <markus.klein@typo3.org>
Mon, 4 Mar 2019 19:36:44 +0000 (20:36 +0100)
committerBenni Mack <benni@typo3.org>
Mon, 4 Mar 2019 20:01:15 +0000 (21:01 +0100)
Capture possible errors due to invalid regex for redirects.
Log those errors as warnings.
Additionally the placeholder text of the source field is enhanced
with a proper example for a regex.

Resolves: #87744
Releases: master, 9.5
Change-Id: Ia4fa763282d91f9e69e2050df3a26c50633ee08b
Reviewed-on: https://review.typo3.org/c/59817
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/redirects/Classes/Service/RedirectService.php
typo3/sysext/redirects/Resources/Private/Language/locallang_module_redirect.xlf

index 7d6dbd9..554d756 100644 (file)
@@ -79,8 +79,11 @@ class RedirectService implements LoggerAwareInterface
             if (!empty($allRedirects[$domainName]['regexp'])) {
                 $allRegexps = array_keys($allRedirects[$domainName]['regexp']);
                 foreach ($allRegexps as $regexp) {
-                    if (preg_match($regexp, $path)) {
+                    $matchResult = @preg_match($regexp, $path);
+                    if ($matchResult) {
                         $possibleRedirects += $allRedirects[$domainName]['regexp'][$regexp];
+                    } elseif ($matchResult === false) {
+                        $this->logger->warning('Invalid regex in redirect', ['regex' => $regexp]);
                     }
                 }
             }
index 2ab5406..cfa6e03 100644 (file)
@@ -65,7 +65,7 @@
                                <source>Source Path</source>
                        </trans-unit>
                        <trans-unit id="source_path.placeholder">
-                               <source>/my-path/</source>
+                               <source>/my-path/ or #^/my-path/$# (when regex enabled)</source>
                        </trans-unit>
                        <trans-unit id="destination">
                                <source>Destination</source>