Skip to content

Commit

Permalink
FIX Encode URLSegment to support multibyte member profile URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
robbieaverill committed Sep 3, 2017
1 parent a212db3 commit 2631175
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 8 deletions.
2 changes: 1 addition & 1 deletion code/extensions/BlogMemberExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class BlogMemberExtension extends DataExtension
* @var array
*/
private static $db = array(
'URLSegment' => 'Varchar',
'URLSegment' => 'Varchar(255)',
'BlogProfileSummary' => 'Text',
);

Expand Down
20 changes: 13 additions & 7 deletions code/model/Blog.php
Original file line number Diff line number Diff line change
Expand Up @@ -708,8 +708,10 @@ public function getCurrentProfile()
$urlSegment = $this->request->param('URLSegment');

if ($urlSegment) {
$filter = URLSegmentFilter::create();

return Member::get()
->filter('URLSegment', $urlSegment)
->filter('URLSegment', $filter->filter($urlSegment))
->first();
}

Expand Down Expand Up @@ -860,8 +862,10 @@ public function getCurrentTag()
$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;
Expand Down Expand Up @@ -904,8 +908,10 @@ public function getCurrentCategory()
$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;
Expand Down Expand Up @@ -1098,7 +1104,7 @@ public function getRSSLink()
{
return $this->Link('rss');
}

/**
* Displays an RSS feed of the given blog posts.
*
Expand All @@ -1115,11 +1121,11 @@ protected function rssFeed($blogPosts, $link)

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) {
Expand Down
40 changes: 40 additions & 0 deletions tests/BlogFunctionalTest.php
Original file line number Diff line number Diff line change
@@ -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());
}
}
22 changes: 22 additions & 0 deletions tests/BlogFunctionalTest.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2631175

Please sign in to comment.