FIX Encode URLSegment to support multibyte member profile URLs

This commit is contained in:
Robbie Averill 2017-09-01 12:06:29 +12:00
parent a212db35b7
commit 26311750b9
4 changed files with 76 additions and 8 deletions

View File

@ -12,7 +12,7 @@ class BlogMemberExtension extends DataExtension
* @var array
*/
private static $db = array(
'URLSegment' => 'Varchar',
'URLSegment' => 'Varchar(255)',
'BlogProfileSummary' => 'Text',
);

View File

@ -708,8 +708,10 @@ class Blog_Controller extends Page_Controller
$urlSegment = $this->request->param('URLSegment');
if ($urlSegment) {
$filter = URLSegmentFilter::create();
return Member::get()
->filter('URLSegment', $urlSegment)
->filter('URLSegment', $filter->filter($urlSegment))
->first();
}
@ -860,8 +862,10 @@ class Blog_Controller extends Page_Controller
$dataRecord = $this->dataRecord;
$tag = $this->request->param('Tag');
if ($tag) {
$filter = URLSegmentFilter::create();
return $dataRecord->Tags()
->filter('URLSegment', array($tag, rawurlencode($tag)))
->filter('URLSegment', array($tag, $filter->filter($tag)))
->first();
}
return null;
@ -904,8 +908,10 @@ class Blog_Controller extends Page_Controller
$dataRecord = $this->dataRecord;
$category = $this->request->param('Category');
if ($category) {
$filter = URLSegmentFilter::create();
return $dataRecord->Categories()
->filter('URLSegment', array($category, rawurlencode($category)))
->filter('URLSegment', array($category, $filter->filter($category)))
->first();
}
return null;
@ -1098,7 +1104,7 @@ class Blog_Controller extends Page_Controller
{
return $this->Link('rss');
}
/**
* Displays an RSS feed of the given blog posts.
*
@ -1115,11 +1121,11 @@ class Blog_Controller extends Page_Controller
return $rss->outputToBrowser();
}
/**
/**
* Returns true if the $Rss sub-action for categories/tags has been set to "rss"
*/
private function isRSS()
private function isRSS()
{
$rss = $this->request->param('Rss');
if(is_string($rss) && strcasecmp($rss, "rss") == 0) {

View File

@ -0,0 +1,40 @@
<?php
class BlogFunctionalTest extends FunctionalTest
{
protected static $fixture_file = 'BlogFunctionalTest.yml';
protected static $use_draft_site = true;
public function setUp()
{
Config::inst()->update('URLSegmentFilter', 'default_allow_multibyte', true);
parent::setUp();
i18n::set_locale('fa_IR');
}
public function testBlogWithMultibyteUrl()
{
$result = $this->get('آبید');
$this->assertEquals(200, $result->getStatusCode());
}
public function testMemberProfileWithMultibyteUrlAndName()
{
$result = $this->get('آبید/profile/عبّاس-آبان');
$this->assertEquals(200, $result->getStatusCode());
$this->assertContains('My Blog Post', $result->getBody());
}
public function testMemberProfileWithMultibyteUrlAndEnglishName()
{
$result = $this->get('آبید/profile/bob-jones');
$this->assertEquals(200, $result->getStatusCode());
$this->assertContains('My Blog Post', $result->getBody());
}
}

View File

@ -0,0 +1,22 @@
Member:
member_a:
FirstName: عبّاس
Surname: آبان
Email: foo@example.com
member_b:
FirstName: Bob
Surname: Jones
Email: bobjones@example.com
Blog:
blog_a:
URLSegment: آبید
Title: My Blog
BlogPost:
blogpost_a:
Title: My Blog Post
URLSegment: آبیدآبید
PublishDate: '2017-08-01 00:00:00'
Parent: =>Blog.blog_a
Authors: =>Member.member_a, =>Member.member_b