From 27a51ed7edccd18a3f0242056660f8adbc1d1087 Mon Sep 17 00:00:00 2001 From: Simon Welsh Date: Fri, 23 Dec 2011 10:22:45 +1300 Subject: [PATCH 1/2] BUGFIX Namespaced classes were always having their namespace prepended to their base class --- core/manifest/ClassManifest.php | 2 +- tests/core/manifest/NamespacedClassManifestTest.php | 11 ++++++----- .../module/classes/ClassH.php | 8 ++++++++ 3 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 tests/core/manifest/fixtures/namespaced_classmanifest/module/classes/ClassH.php diff --git a/core/manifest/ClassManifest.php b/core/manifest/ClassManifest.php index a1e38d7bd..5bbe0c3bb 100644 --- a/core/manifest/ClassManifest.php +++ b/core/manifest/ClassManifest.php @@ -354,7 +354,7 @@ class SS_ClassManifest { $extends = isset($class['extends']) ? implode('', $class['extends']) : null; $implements = isset($class['interfaces']) ? $class['interfaces'] : null; - if($extends && $extends[0] != '/\\') { + if($extends && $extends[0] != '\\') { $extends = $namespace . $extends; } elseif($extends) { $extends = substr($extends, 1); diff --git a/tests/core/manifest/NamespacedClassManifestTest.php b/tests/core/manifest/NamespacedClassManifestTest.php index c529ca996..f4dd418c4 100644 --- a/tests/core/manifest/NamespacedClassManifestTest.php +++ b/tests/core/manifest/NamespacedClassManifestTest.php @@ -44,7 +44,8 @@ class NamespacedClassManifestTest extends SapphireTest { 'sapphire\test\classd' => "{$this->base}/module/classes/ClassD.php", 'sapphire\test\classe' => "{$this->base}/module/classes/ClassE.php", 'sapphire\test\classf' => "{$this->base}/module/classes/ClassF.php", - 'sapphire\test\classg' => "{$this->base}/module/classes/ClassG.php" + 'sapphire\test\classg' => "{$this->base}/module/classes/ClassG.php", + 'sapphire\test\classh' => "{$this->base}/module/classes/ClassH.php" ); $this->assertEquals($expect, $this->manifest->getClasses()); @@ -52,13 +53,13 @@ class NamespacedClassManifestTest extends SapphireTest { public function testGetClassNames() { $this->assertEquals( - array('sapphire\test\classa', 'sapphire\test\classb', 'sapphire\test\classc', 'sapphire\test\classd', 'sapphire\test\classe', 'sapphire\test\classf', 'sapphire\test\classg'), + array('sapphire\test\classa', 'sapphire\test\classb', 'sapphire\test\classc', 'sapphire\test\classd', 'sapphire\test\classe', 'sapphire\test\classf', 'sapphire\test\classg', 'sapphire\test\classh'), $this->manifest->getClassNames()); } public function testGetDescendants() { $expect = array( - 'sapphire\test\classa' => array('sapphire\test\ClassB') + 'sapphire\test\classa' => array('sapphire\test\ClassB', 'sapphire\test\ClassH'), ); $this->assertEquals($expect, $this->manifest->getDescendants()); @@ -66,8 +67,8 @@ class NamespacedClassManifestTest extends SapphireTest { public function testGetDescendantsOf() { $expect = array( - 'SAPPHIRE\TEST\CLASSA' => array('sapphire\test\ClassB'), - 'sapphire\test\classa' => array('sapphire\test\ClassB'), + 'SAPPHIRE\TEST\CLASSA' => array('sapphire\test\ClassB', 'sapphire\test\ClassH'), + 'sapphire\test\classa' => array('sapphire\test\ClassB', 'sapphire\test\ClassH'), ); foreach ($expect as $class => $desc) { diff --git a/tests/core/manifest/fixtures/namespaced_classmanifest/module/classes/ClassH.php b/tests/core/manifest/fixtures/namespaced_classmanifest/module/classes/ClassH.php new file mode 100644 index 000000000..17597aafb --- /dev/null +++ b/tests/core/manifest/fixtures/namespaced_classmanifest/module/classes/ClassH.php @@ -0,0 +1,8 @@ + Date: Fri, 23 Dec 2011 10:38:37 +1300 Subject: [PATCH 2/2] BUGFIX Sanitise keys and tags before using them with Zend_Cache. --- model/Aggregate.php | 11 +++++++---- view/SSTemplateParser.php.inc | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/model/Aggregate.php b/model/Aggregate.php index 061618473..77a483db3 100644 --- a/model/Aggregate.php +++ b/model/Aggregate.php @@ -48,9 +48,12 @@ class Aggregate extends ViewableData { if (!$class || $class == 'DataObject') { $cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array('aggregate')); - } - else { - $cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, ClassInfo::ancestry($class)); + } else { + $tags = ClassInfo::ancestry($class); + foreach($tags as &$tag) { + $tag = preg_replace('/[^a-zA-Z0-9_]/', '_', $tag); + } + $cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, $tags); } } @@ -108,7 +111,7 @@ class Aggregate extends ViewableData { if (!($result = $cache->load($cachekey))) { $result = (string)$query->execute()->value(); if (!$result) $result = '0'; - $cache->save($result, null, array('aggregate', $this->type)); + $cache->save($result, null, array('aggregate', preg_replace('/[^a-zA-Z0-9_]/', '_', $this->type))); } return $result; diff --git a/view/SSTemplateParser.php.inc b/view/SSTemplateParser.php.inc index 63dca3116..105555dec 100644 --- a/view/SSTemplateParser.php.inc +++ b/view/SSTemplateParser.php.inc @@ -490,6 +490,7 @@ class SSTemplateParser extends Parser { $block = ++$res['subblocks']; // Build the key for this block from the passed cache key, the block index, and the sha hash of the template itself $key = "'" . sha1($sub['php']) . (isset($res['key']) && $res['key'] ? "_'.sha1(".$res['key'].")" : "'") . ".'_$block'"; + $key = preg_replace('/[^a-zA-Z0-9_]/', '_', $key); // Get any condition $condition = isset($res['condition']) ? $res['condition'] : '';