diff --git a/code/Controllers/CMSSiteTreeFilter.php b/code/Controllers/CMSSiteTreeFilter.php index a23dc4a8..56ab9978 100644 --- a/code/Controllers/CMSSiteTreeFilter.php +++ b/code/Controllers/CMSSiteTreeFilter.php @@ -5,6 +5,7 @@ namespace SilverStripe\CMS\Controllers; use SilverStripe\Admin\LeftAndMain_SearchFilter; use SilverStripe\CMS\Model\SiteTree; use SilverStripe\Core\ClassInfo; +use SilverStripe\Core\Convert; use SilverStripe\Core\Injector\Injectable; use SilverStripe\Forms\DateField; use SilverStripe\ORM\DataList; @@ -203,13 +204,19 @@ abstract class CMSSiteTreeFilter implements LeftAndMain_SearchFilter switch ($name) { case 'Term': $query = $query->filterAny(array( - 'URLSegment:PartialMatch' => $val, + 'URLSegment:PartialMatch' => Convert::raw2url($val), 'Title:PartialMatch' => $val, 'MenuTitle:PartialMatch' => $val, 'Content:PartialMatch' => $val )); break; + case 'URLSegment': + $query = $query->filter([ + 'URLSegment:PartialMatch' => Convert::raw2url($val), + ]); + break; + case 'LastEditedFrom': $fromDate = new DateField(null, null, $val); $query = $query->filter("LastEdited:GreaterThanOrEqual", $fromDate->dataValue().' 00:00:00'); diff --git a/tests/php/Controllers/CMSSiteTreeFilterTest.php b/tests/php/Controllers/CMSSiteTreeFilterTest.php index 2093de55..abb33880 100644 --- a/tests/php/Controllers/CMSSiteTreeFilterTest.php +++ b/tests/php/Controllers/CMSSiteTreeFilterTest.php @@ -47,6 +47,17 @@ class CMSSiteTreeFilterTest extends SapphireTest ); } + public function testUrlSegmentFilter() + { + $page = $this->objFromFixture(Page::class, 'page8'); + + $filter = CMSSiteTreeFilter_Search::create(['Term' => 'lake-wanaka+adventure']); + $this->assertTrue($filter->isPageIncluded($page)); + + $filter = CMSSiteTreeFilter_Search::create(['URLSegment' => 'lake-wanaka+adventure']); + $this->assertTrue($filter->isPageIncluded($page)); + } + public function testIncludesParentsForNestedMatches() { $parent = $this->objFromFixture('Page', 'page3'); diff --git a/tests/php/Controllers/CMSSiteTreeFilterTest.yml b/tests/php/Controllers/CMSSiteTreeFilterTest.yml index 7e23ae16..c90e520a 100644 --- a/tests/php/Controllers/CMSSiteTreeFilterTest.yml +++ b/tests/php/Controllers/CMSSiteTreeFilterTest.yml @@ -29,3 +29,6 @@ Page: page3b: Parent: =>Page.page3 Title: Page 3b + page8: + Title: EncodedUrlSegment + URLSegment: lake-wanaka+adventure