From eba33899062016221b33c3944bf47feda9a321ed Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Sat, 21 Jan 2023 08:36:44 +1300 Subject: [PATCH] fix: handle exceptions when using /0 as a URL --- code/Controllers/ModelAsController.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/code/Controllers/ModelAsController.php b/code/Controllers/ModelAsController.php index 8f9233ca65..0165a3fbab 100644 --- a/code/Controllers/ModelAsController.php +++ b/code/Controllers/ModelAsController.php @@ -118,8 +118,9 @@ public function handleRequest(HTTPRequest $request) public function getNestedController() { $request = $this->getRequest(); + $urlSegment = $request->param('URLSegment'); - if (!$URLSegment = $request->param('URLSegment')) { + if ($urlSegment === null || $urlSegment === '') { throw new Exception('ModelAsController->getNestedController(): was not passed a URLSegment value.'); } @@ -130,13 +131,14 @@ public function getNestedController() // url encode unless it's multibyte (already pre-encoded in the database) $filter = URLSegmentFilter::create(); + if (!$filter->getAllowMultibyte()) { - $URLSegment = rawurlencode($URLSegment ?? ''); + $urlSegment = rawurlencode($urlSegment ?? ''); } // Select child page $tableName = DataObject::singleton(SiteTree::class)->baseTable(); - $conditions = [sprintf('"%s"."URLSegment"', $tableName) => $URLSegment]; + $conditions = [sprintf('"%s"."URLSegment"', $tableName) => $urlSegment]; if (SiteTree::config()->get('nested_urls')) { $conditions[] = [sprintf('"%s"."ParentID"', $tableName) => 0]; }