From 26311750b984488c02480cb27b18b566c562e004 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Fri, 1 Sep 2017 12:06:29 +1200 Subject: [PATCH 1/2] FIX Encode URLSegment to support multibyte member profile URLs --- code/extensions/BlogMemberExtension.php | 2 +- code/model/Blog.php | 20 ++++++++----- tests/BlogFunctionalTest.php | 40 +++++++++++++++++++++++++ tests/BlogFunctionalTest.yml | 22 ++++++++++++++ 4 files changed, 76 insertions(+), 8 deletions(-) create mode 100644 tests/BlogFunctionalTest.php create mode 100644 tests/BlogFunctionalTest.yml diff --git a/code/extensions/BlogMemberExtension.php b/code/extensions/BlogMemberExtension.php index f45a88b..6381598 100644 --- a/code/extensions/BlogMemberExtension.php +++ b/code/extensions/BlogMemberExtension.php @@ -12,7 +12,7 @@ class BlogMemberExtension extends DataExtension * @var array */ private static $db = array( - 'URLSegment' => 'Varchar', + 'URLSegment' => 'Varchar(255)', 'BlogProfileSummary' => 'Text', ); diff --git a/code/model/Blog.php b/code/model/Blog.php index 0ce1b08..daf70af 100644 --- a/code/model/Blog.php +++ b/code/model/Blog.php @@ -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) { diff --git a/tests/BlogFunctionalTest.php b/tests/BlogFunctionalTest.php new file mode 100644 index 0000000..feb419c --- /dev/null +++ b/tests/BlogFunctionalTest.php @@ -0,0 +1,40 @@ +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()); + } +} diff --git a/tests/BlogFunctionalTest.yml b/tests/BlogFunctionalTest.yml new file mode 100644 index 0000000..f4c1110 --- /dev/null +++ b/tests/BlogFunctionalTest.yml @@ -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 From 3bb197936ff08ebbefe1dd9d7abc1dc3a4ae8371 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Mon, 4 Sep 2017 06:49:34 +1200 Subject: [PATCH 2/2] Always use precise on Travis --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index aa61385..651cf6c 100755 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,8 @@ language: php sudo: false +dist: precise + addons: apt: packages: