From dba8ff46ea2ab7d3865f8b2ed92ee14f77552aef Mon Sep 17 00:00:00 2001 From: Lonnie Ezell Date: Sun, 19 Apr 2020 23:59:52 -0500 Subject: [PATCH] Strip directory separators from auto-generated cell cache name. Fixes #2821 --- system/View/Cell.php | 4 +++- tests/system/View/CellTest.php | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/system/View/Cell.php b/system/View/Cell.php index a7e79e9c09aa..e8878168c11f 100644 --- a/system/View/Cell.php +++ b/system/View/Cell.php @@ -110,7 +110,9 @@ public function render(string $library, $params = null, int $ttl = 0, string $ca list($class, $method) = $this->determineClass($library); // Is it cached? - $cacheName = ! empty($cacheName) ? $cacheName : $class . $method . md5(serialize($params)); + $cacheName = ! empty($cacheName) + ? $cacheName + : str_replace(['\\', '/'], '', $class) . $method . md5(serialize($params)); if (! empty($this->cache) && $output = $this->cache->get($cacheName)) { diff --git a/tests/system/View/CellTest.php b/tests/system/View/CellTest.php index b1ebe2f6bd2f..be4fa3039668 100644 --- a/tests/system/View/CellTest.php +++ b/tests/system/View/CellTest.php @@ -232,6 +232,21 @@ public function testRenderCached() $this->assertEquals(implode(',', $expected), $this->cell->render('\Tests\Support\View\SampleClass::echobox', $params, 1, 'rememberme')); } + public function testRenderCachedAutoName() + { + $params = 'one=two,three=four'; + $expected = [ + 'one' => 'two', + 'three' => 'four', + ]; + + $this->assertEquals(implode(',', $expected), $this->cell->render('\Tests\Support\View\SampleClass::echobox', $params, 60)); + $params = 'one=six,three=five'; + // When auto-generating it takes the params as part of cachename, so it wouldn't have actually cached this, but + // we want to make sure it doesn't throw us a curveball here. + $this->assertEquals('six,five', $this->cell->render('\Tests\Support\View\SampleClass::echobox', $params, 1)); + } + //-------------------------------------------------------------------- public function testParametersMatch()