Merge pull request #466 from robbieaverill/pulls/2.4/multibyte-member-profiles

FIX Encode URLSegment to support multibyte member profile URLs
This commit is contained in:
Michael Strong 2017-09-06 09:37:47 +12:00 committed by GitHub
commit 66f8b80943
5 changed files with 78 additions and 8 deletions

View File

@ -2,6 +2,8 @@ language: php
sudo: false sudo: false
dist: precise
addons: addons:
apt: apt:
packages: packages:

View File

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

View File

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