FIX Multibyte URL encoding for blog profiles, and encoded params in functional tests

This commit is contained in:
Robbie Averill 2019-02-05 16:50:21 +03:00
parent 9c10a86de8
commit cbbe8b94db
2 changed files with 9 additions and 5 deletions

View File

@ -106,12 +106,16 @@ class BlogController extends PageController
public function getCurrentProfile() public function getCurrentProfile()
{ {
$urlSegment = $this->request->param('URLSegment'); $urlSegment = $this->request->param('URLSegment');
if ($urlSegment) { if ($urlSegment) {
$filter = URLSegmentFilter::create(); $filter = URLSegmentFilter::create();
// url encode unless it's multibyte (already pre-encoded in the database)
// see https://github.com/silverstripe/silverstripe-cms/pull/2384
if (!$filter->getAllowMultibyte()) {
$urlSegment = rawurlencode($urlSegment);
}
return Member::get() return Member::get()
->filter('URLSegment', $filter->filter($urlSegment)) ->filter('URLSegment', $urlSegment)
->first(); ->first();
} }

View File

@ -23,14 +23,14 @@ class BlogFunctionalTest extends FunctionalTest
public function testBlogWithMultibyteUrl() public function testBlogWithMultibyteUrl()
{ {
$result = $this->get('آبید'); $result = $this->get(rawurlencode('آبید'));
$this->assertEquals(200, $result->getStatusCode()); $this->assertEquals(200, $result->getStatusCode());
} }
public function testMemberProfileWithMultibyteUrlAndName() public function testMemberProfileWithMultibyteUrlAndName()
{ {
$result = $this->get('آبید/profile/عبّاس-آبان'); $result = $this->get(rawurlencode('آبید') . '/profile/' . rawurlencode('عبّاس-آبان'));
$this->assertEquals(200, $result->getStatusCode()); $this->assertEquals(200, $result->getStatusCode());
$this->assertContains('My Blog Post', $result->getBody()); $this->assertContains('My Blog Post', $result->getBody());
@ -38,7 +38,7 @@ class BlogFunctionalTest extends FunctionalTest
public function testMemberProfileWithMultibyteUrlAndEnglishName() public function testMemberProfileWithMultibyteUrlAndEnglishName()
{ {
$result = $this->get('آبید/profile/bob-jones'); $result = $this->get(rawurlencode('آبید') . '/profile/bob-jones');
$this->assertEquals(200, $result->getStatusCode()); $this->assertEquals(200, $result->getStatusCode());
$this->assertContains('My Blog Post', $result->getBody()); $this->assertContains('My Blog Post', $result->getBody());