Skip to content

Commit

Permalink
Merge pull request #402 from micmania1/fix-376-url
Browse files Browse the repository at this point in the history
FIX #376 allow multibyte chars in url segment
  • Loading branch information
Damian Mooyman committed Jun 29, 2016
2 parents 35c5357 + e4c3b87 commit a21b503
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
6 changes: 6 additions & 0 deletions code/extensions/URLSegmentExtension.php
Expand Up @@ -36,6 +36,12 @@ public function generateURLSegment($increment = null)
{
$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)) {
Expand Down
16 changes: 16 additions & 0 deletions tests/BlogCategoryTest.php
Expand Up @@ -52,6 +52,22 @@ public function testBlogPosts()
$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();
Expand Down
16 changes: 16 additions & 0 deletions tests/BlogTagTest.php
Expand Up @@ -52,6 +52,22 @@ public function testBlogPosts()
$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.
*/
Expand Down

0 comments on commit a21b503

Please sign in to comment.