Browse files

BUGFIX Fixed publication of multibyte URLSegment in SiteTree->onBefor…

…eWrite(), was wrongly detecting a change and double encoding
  • Loading branch information...
1 parent 77e52d6 commit 85633229718ad1ee2d9690deab3891ef5d577dc3 @chillu chillu committed May 8, 2012
Showing with 23 additions and 1 deletion.
  1. +3 −1 code/model/SiteTree.php
  2. +20 −0 tests/model/SiteTreeTest.php
View
4 code/model/SiteTree.php
@@ -1384,7 +1384,9 @@ protected function onBeforeWrite() {
// If there is no URLSegment set, generate one from Title
if((!$this->URLSegment || $this->URLSegment == 'new-page') && $this->Title) {
$this->URLSegment = $this->generateURLSegment($this->Title);
- } else if($this->isChanged('URLSegment')) {
+ } else if($this->isChanged('URLSegment', 2)) {
+ // Do a strict check on change level, to avoid double encoding caused by
+ // bogus changes through forceChange()
$filter = URLSegmentFilter::create();
$this->URLSegment = $filter->filter($this->URLSegment);
// If after sanitising there is no URLSegment, give it a reasonable default
View
20 tests/model/SiteTreeTest.php
@@ -720,6 +720,26 @@ public function testValidURLSegmentControllerConflicts() {
$sitetree->URLSegment = 'valid';
$this->assertTrue($sitetree->validURLSegment(), 'Valid URLSegment values are allowed');
}
+
+ public function testURLSegmentMultiByte() {
+ $origAllow = URLSegmentFilter::$default_allow_multibyte;
+ URLSegmentFilter::$default_allow_multibyte = true;
+ $sitetree = new SiteTree();
+ $sitetree->write();
+
+ $sitetree->URLSegment = 'brötchen';
+ $sitetree->write();
+ $sitetree = DataObject::get_by_id('SiteTree', $sitetree->ID, false);
+ $this->assertEquals($sitetree->URLSegment, rawurlencode('brötchen'));
+
+ $sitetree->publish('Stage', 'Live');
+ $sitetree = DataObject::get_by_id('SiteTree', $sitetree->ID, false);
+ $this->assertEquals($sitetree->URLSegment, rawurlencode('brötchen'));
+ $sitetreeLive = Versioned::get_one_by_stage('SiteTree', 'Live', '"SiteTree"."ID" = ' .$sitetree->ID, false);
+ $this->assertEquals($sitetreeLive->URLSegment, rawurlencode('brötchen'));
+
+ URLSegmentFilter::$default_allow_multibyte = $origAllow;
+ }
public function testVersionsAreCreated() {
$p = new Page();

0 comments on commit 8563322

Please sign in to comment.