Normalize custom URLs
authorAlexander Ebert <ebert@woltlab.com>
Sat, 14 Oct 2023 16:04:29 +0000 (18:04 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sat, 14 Oct 2023 16:04:29 +0000 (18:04 +0200)
See https://www.woltlab.com/community/thread/302049-startseite-wird-nach-update-auf-woltlab-suite-6-0-nicht-angezeigt-es-erfolgt-ein/?postID=1941879#post1941879

wcfsetup/install/files/lib/acp/form/PageAddForm.class.php

index 2d24128a6f55bcdfb243d8a25be34e6326f28c5f..ded244a96aba66d75530dbd94c30d23a8dccf677 100644 (file)
@@ -316,7 +316,7 @@ class PageAddForm extends AbstractForm
         }
 
         if (isset($_POST['customURL']) && \is_array($_POST['customURL'])) {
-            $this->customURL = \array_map('mb_strtolower', ArrayUtil::trim($_POST['customURL']));
+            $this->customURL = \array_map($this->normalizeCustomUrl(...), ArrayUtil::trim($_POST['customURL']));
         }
         if (isset($_POST['title']) && \is_array($_POST['title'])) {
             $this->title = ArrayUtil::trim($_POST['title']);
@@ -502,6 +502,20 @@ class PageAddForm extends AbstractForm
         }
     }
 
+    /**
+     * Replaces consecutive slashes with a single slash and trims any leading
+     * or trailing slashes.
+     *
+     * @since 6.0
+     */
+    protected function normalizeCustomUrl(string $customUrl): string
+    {
+        $customUrl = \mb_strtolower($customUrl);
+        $customUrl = \preg_replace('~/{2,}~', '/', $customUrl);
+
+        return \trim($customUrl, '/');
+    }
+
     /**
      * Validates page title.
      *