mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #2871 from feejin/urlsegment-trailing-space
BUG Trim URLSegment before applying replacements in filter
This commit is contained in:
commit
cad863204c
@ -33,7 +33,8 @@ class URLSegmentFilter extends Object {
|
||||
'/[_.]+/u' => '-', // underscores and dots to dashes
|
||||
'/[^A-Za-z0-9\-]+/u' => '', // remove non-ASCII chars, only allow alphanumeric and dashes
|
||||
'/[\-]{2,}/u' => '-', // remove duplicate dashes
|
||||
'/^[\-]+/u' => '' // Remove all leading dashes
|
||||
'/^[\-]+/u' => '', // Remove all leading dashes
|
||||
'/[\-]+$/u' => '' // Remove all trailing dashes
|
||||
);
|
||||
|
||||
/**
|
||||
|
@ -41,8 +41,8 @@ class URLSegmentFilterTest extends SapphireTest {
|
||||
public function testReplacesCommonNonAsciiCharacters() {
|
||||
$f = new URLSegmentFilter();
|
||||
$this->assertEquals(
|
||||
urlencode('aa1-'),
|
||||
$f->filter('Aa1~!@#$%^*()_`-=;\':"[]\{}|,./<>?')
|
||||
urlencode('aa1-a'),
|
||||
$f->filter('Aa1~!@#$%^*()_`-=;\':"[]\{}|,./<>?a')
|
||||
);
|
||||
}
|
||||
|
||||
@ -82,4 +82,9 @@ class URLSegmentFilterTest extends SapphireTest {
|
||||
$this->assertEquals('url-has-leading-dashes', $filter->filter('---url-has-leading-dashes'));
|
||||
}
|
||||
|
||||
public function testReplacesTrailingDashes() {
|
||||
$filter = new URLSegmentFilter();
|
||||
$this->assertEquals('url-has-trailing-dashes', $filter->filter('url-has-trailing-dashes--'));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user