[BUGFIX] Allow to access pages with "index.php?id=123" 14/59414/6
authorMichael Giek <michael.giek@b13.de>
Fri, 11 Jan 2019 15:22:24 +0000 (16:22 +0100)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Fri, 11 Jan 2019 21:42:57 +0000 (22:42 +0100)
Currently, the SiteMatcher checks for "?id=123&L=123" for special
treatment when Site Handling is enabled.

However, it should be possible to only access
www.example.com/index.php?id=123, without the "L" parameter,
for pages with Site-handling.

Without the patch, the language is not resolved, and a redirect
to /fr/ (or whatever default language prefix is given) is made.

Tests are adapted so IDs with ?id=1000 are not redirected
anymore.

Resolves: #87412
Releases: master, 9.5
Change-Id: Ied3df51359346996c6a889576b95516c008b734f
Reviewed-on: https://review.typo3.org/59414
Tested-by: TYPO3com <noreply@typo3.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/core/Classes/Routing/SiteMatcher.php
typo3/sysext/frontend/Tests/Functional/SiteHandling/SiteRequestTest.php

index 2586667..e72abde 100644 (file)
@@ -84,6 +84,7 @@ class SiteMatcher implements SingletonInterface
     {
         $site = null;
         $language = null;
+        $defaultLanguage = null;
 
         $pageId = $request->getQueryParams()['id'] ?? $request->getParsedBody()['id'] ?? 0;
 
@@ -96,6 +97,9 @@ class SiteMatcher implements SingletonInterface
                 $languageId = $request->getQueryParams()['L'] ?? $request->getParsedBody()['L'] ?? null;
                 if ($languageId !== null) {
                     $language = $site->getLanguageById((int)$languageId);
+                } else {
+                    // Use this later below
+                    $defaultLanguage = $site->getDefaultLanguage();
                 }
             } catch (SiteNotFoundException $e) {
                 // No site found by the given page
@@ -105,9 +109,9 @@ class SiteMatcher implements SingletonInterface
             }
         }
 
-        // No language found at this point means that the URL was not used with a valid "?id" parameter
+        // No language found at this point means that the URL was not used with a valid "?id=1&L=2" parameter
         // which resulted in a site / language combination that was found. Now, the matching is done
-        // on the incoming URL
+        // on the incoming URL.
         if (!($language instanceof SiteLanguage)) {
             $collection = $this->getRouteCollectionForAllSites();
             $context = new RequestContext(
@@ -123,7 +127,15 @@ class SiteMatcher implements SingletonInterface
             $matcher = new UrlMatcher($collection, $context);
             try {
                 $result = $matcher->match($request->getUri()->getPath());
-                return new SiteRouteResult($request->getUri(), $result['site'], $result['language'], $result['tail']);
+                return new SiteRouteResult(
+                    $request->getUri(),
+                    $result['site'],
+                    // if no language is found, this usually results due to "/" called instead of "/fr/"
+                    // but it could also be the reason that "/index.php?id=23" was called, so the default
+                    // language is used as a fallback here then.
+                    $result['language'] ?? $defaultLanguage,
+                    $result['tail']
+                );
             } catch (NoConfigurationException | ResourceNotFoundException $e) {
                 // No site+language combination found so far
             }
@@ -144,7 +156,12 @@ class SiteMatcher implements SingletonInterface
                 $context->setHost(implode('.', $host));
                 try {
                     $result = $matcher->match($request->getUri()->getPath());
-                    return new SiteRouteResult($request->getUri(), $result['site'], $result['language'], $result['tail']);
+                    return new SiteRouteResult(
+                        $request->getUri(),
+                        $result['site'],
+                        $result['language'],
+                        $result['tail']
+                    );
                 } catch (NoConfigurationException | ResourceNotFoundException $e) {
                     array_shift($host);
                 }
index ee6242a..e2320de 100644 (file)
@@ -108,8 +108,7 @@ class SiteRequestTest extends AbstractTestCase
         ];
 
         $queries = [
-            '?',
-            '?id=1000',
+            '',
         ];
 
         return $this->wrapInArray(