Skip to content

Commit

Permalink
fix: handle exceptions when using /0 as a URL
Browse files Browse the repository at this point in the history
  • Loading branch information
wilr committed Jan 23, 2023
1 parent 9907209 commit eba3389
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions code/Controllers/ModelAsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}

Expand All @@ -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];
}
Expand Down

0 comments on commit eba3389

Please sign in to comment.