[BUGFIX] Support non ASCII url slugs 96/59796/3
authorGuido Schmechel <guido.schmechel@brandung.de>
Sun, 24 Feb 2019 21:49:48 +0000 (22:49 +0100)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Fri, 1 Mar 2019 11:37:25 +0000 (12:37 +0100)
Resolves: #87295
Releases: master, 9.5
Change-Id: Ib4fb1a8283c79a02cbc8cb52d91e2448ad9292ec
Reviewed-on: https://review.typo3.org/c/59796
Tested-by: Benni Mack <benni@typo3.org>
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Jürgen Venne <venne@schaffrath-digital.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Reviewed-by: Jürgen Venne <venne@schaffrath-digital.de>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/core/Classes/DataHandling/SlugHelper.php
typo3/sysext/core/Tests/Unit/DataHandling/SlugHelperTest.php
typo3/sysext/install/Classes/Updates/PopulatePageSlugs.php

index c2ec0c7..2a3c37b 100644 (file)
@@ -122,10 +122,6 @@ class SlugHelper
 
         // Ensure slug is lower cased after all replacement was done
         $slug = mb_strtolower($slug, 'utf-8');
-        // keep slashes: re-convert them after rawurlencode did everything
-        $slug = rawurlencode($slug);
-        // @todo: add a test and see if we need this
-        $slug = str_replace('%2F', '/', $slug);
         // Extract slug, thus it does not have wrapping fallback and slash characters
         $extractedSlug = $this->extract($slug);
         // Remove trailing and beginning slashes, except if the trailing slash was added, then we'll re-add it
index 90efdaa..fc364ed 100644 (file)
@@ -120,6 +120,16 @@ class SlugHelperTest extends UnitTestCase
                 'special-chars-«-∑-€-®-†-Ω-¨-ø-π-å-‚-∂-ƒ-©-ª-º-∆-@-¥-≈-ç-√-∫-~-µ-∞-…-–',
                 'special-chars-eur-r-o-oe-p-aa-f-c-a-o-yen-c-u'
             ],
+            'ensure colon and other http related parts are disallowed' => [
+                [],
+                'https://example.com:80/my/page/slug/',
+                'https//examplecom80/my/page/slug/'
+            ],
+            'non-ASCII characters are kept' => [
+                [],
+                'bla-arg应---用-ascii',
+                'bla-arg应-用-ascii'
+            ],
         ];
     }
 
@@ -280,6 +290,16 @@ class SlugHelperTest extends UnitTestCase
                 'special-chars-«-∑-€-®-†-Ω-¨-ø-π-å-‚-∂-ƒ-©-ª-º-∆-@-¥-≈-ç-√-∫-~-µ-∞-…-–',
                 '/special-chars-eur-r-o-oe-p-aa-f-c-a-o-yen-c-u'
             ],
+            'ensure colon and other http related parts are disallowed' => [
+                [],
+                'https://example.com:80/my/page/slug/',
+                '/https//examplecom80/my/page/slug/'
+            ],
+            'chinese' => [
+                [],
+                '应用',
+                '/应用'
+            ],
         ];
     }
 
index 3bfcb6e..752335a 100644 (file)
@@ -226,7 +226,9 @@ class PopulatePageSlugs implements UpgradeWizardInterface
             ->execute();
         $suggestedSlugs = [];
         while ($row = $statement->fetch()) {
-            $suggestedSlugs[(int)$row['page_id']][(int)$row['language_id']] = '/' . trim($row['pagepath'], '/');
+            // rawurldecode ensures that non-ASCII arguments are also migrated
+            $pagePath = rawurldecode($row['pagepath']);
+            $suggestedSlugs[(int)$row['page_id']][(int)$row['language_id']] = '/' . trim($pagePath, '/');
         }
         return $suggestedSlugs;
     }