[BUGFIX] Avoid suffixing base slug again 44/58144/4
authorOliver Hader <oliver@typo3.org>
Mon, 3 Sep 2018 16:51:35 +0000 (18:51 +0200)
committerOliver Hader <oliver.hader@typo3.org>
Mon, 3 Sep 2018 17:48:56 +0000 (19:48 +0200)
When invoking slug generation on an empty or base slug (`/`), the
slug will become `//` - which is invalid and has to be avoided.

Resolves: #86114
Releases: master
Change-Id: I66aac94ec9be7992376806d59b7c3ef1bd0e142a
Reviewed-on: https://review.typo3.org/58144
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Oliver Hader <oliver.hader@typo3.org>
Tested-by: Oliver Hader <oliver.hader@typo3.org>
typo3/sysext/core/Classes/DataHandling/SlugHelper.php
typo3/sysext/core/Tests/Unit/DataHandling/SlugHelperTest.php

index e2a8369..81b8591 100644 (file)
@@ -107,9 +107,11 @@ class SlugHelper
         $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
-        $appendTrailingSlash = substr($slug, -1) === '/';
-        $slug = '/' . $this->extract($slug) . ($appendTrailingSlash ? '/' : '');
+        $appendTrailingSlash = $extractedSlug !== '' && substr($slug, -1) === '/';
+        $slug = '/' . $extractedSlug . ($appendTrailingSlash ? '/' : '');
         return $slug;
     }
 
index 1c9aaf4..81ec25f 100644 (file)
@@ -36,6 +36,21 @@ class SlugHelperTest extends UnitTestCase
                 '',
                 '/',
             ],
+            'existing base' => [
+                [],
+                '/',
+                '/',
+            ],
+            'invalid base' => [
+                [],
+                '//',
+                '/',
+            ],
+            'invalid slug' => [
+                [],
+                '/slug//',
+                '/slug/',
+            ],
             'lowercase characters' => [
                 [],
                 '1AZĂ„',