diff --git a/code/extensions/URLSegmentExtension.php b/code/extensions/URLSegmentExtension.php index 7485adb..2daba19 100644 --- a/code/extensions/URLSegmentExtension.php +++ b/code/extensions/URLSegmentExtension.php @@ -36,6 +36,12 @@ class URLSegmentExtension extends DataExtension { $filter = new URLSegmentFilter(); + // Setting this to on. Because of the UI flow, it would be quite a lot of work + // to support turning this off. (ie. the add by title flow would not work). + // If this becomes a problem we can approach it then. + // @see https://github.com/silverstripe/silverstripe-blog/issues/376 + $filter->setAllowMultibyte(true); + $this->owner->URLSegment = $filter->filter($this->owner->Title); if (is_int($increment)) { diff --git a/tests/BlogCategoryTest.php b/tests/BlogCategoryTest.php index 3acf08a..c29aa95 100755 --- a/tests/BlogCategoryTest.php +++ b/tests/BlogCategoryTest.php @@ -52,6 +52,22 @@ class BlogCategoryTest extends FunctionalTest $this->assertEquals(5, $category->BlogPosts()->count(), 'Category blog post count'); } + /** + * @see https://github.com/silverstripe/silverstripe-blog/issues/376 + */ + public function testAllowMultibyteUrlSegment() + { + $blog = $this->objFromFixture('Blog', 'FirstBlog'); + $cat = new BlogCategory(); + $cat->BlogID = $blog->ID; + $cat->Title = 'تست'; + $cat->write(); + // urlencoded + $this->assertEquals('%D8%AA%D8%B3%D8%AA', $cat->URLSegment); + $link = Controller::join_links($cat->Blog()->Link(), 'category', '%D8%AA%D8%B3%D8%AA'); + $this->assertEquals($link, $cat->getLink()); + } + public function testCanView() { $this->useDraftSite(); diff --git a/tests/BlogTagTest.php b/tests/BlogTagTest.php index ba70dea..dcf886c 100755 --- a/tests/BlogTagTest.php +++ b/tests/BlogTagTest.php @@ -52,6 +52,22 @@ class BlogTagTest extends FunctionalTest $this->assertEquals(1, $tag->BlogPosts()->count(), 'Tag blog post count'); } + /** + * @see https://github.com/silverstripe/silverstripe-blog/issues/376 + */ + public function testAllowMultibyteUrlSegment() + { + $blog = $this->objFromFixture('Blog', 'FirstBlog'); + $tag = new BlogTag(); + $tag->BlogID = $blog->ID; + $tag->Title = 'تست'; + $tag->write(); + // urlencoded + $this->assertEquals('%D8%AA%D8%B3%D8%AA', $tag->URLSegment); + $link = Controller::join_links($tag->Blog()->Link(), 'tag', '%D8%AA%D8%B3%D8%AA'); + $this->assertEquals($link, $tag->getLink()); + } + /** * The first blog can be viewed by anybody. */