Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0da18e0

Browse filesBrowse files
bug #27752 [Cache] provider does not respect option maxIdLength with versioning enabled (Constantine Shtompel)
This PR was squashed before being merged into the 3.4 branch (closes #27752). Discussion ---------- [Cache] provider does not respect option maxIdLength with versioning enabled | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #27746 | License | MIT | Doc PR | Component symfony/cache generates cache item ID longer then maxIdLength when versioning is enabled Commits ------- ba8b63b [Cache] provider does not respect option maxIdLength with versioning enabled
2 parents 3384b2d + ba8b63b commit 0da18e0
Copy full SHA for 0da18e0

File tree

2 files changed

+29
-1
lines changed
Filter options

2 files changed

+29
-1
lines changed

‎src/Symfony/Component/Cache/Tests/Adapter/MaxIdLengthAdapterTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Tests/Adapter/MaxIdLengthAdapterTest.php
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,34 @@ public function testLongKey()
3434
$cache->hasItem(str_repeat('-', 39));
3535
}
3636

37+
public function testLongKeyVersioning()
38+
{
39+
$cache = $this->getMockBuilder(MaxIdLengthAdapter::class)
40+
->setConstructorArgs(array(str_repeat('-', 26)))
41+
->getMock();
42+
43+
$reflectionClass = new \ReflectionClass(AbstractAdapter::class);
44+
45+
$reflectionMethod = $reflectionClass->getMethod('getId');
46+
$reflectionMethod->setAccessible(true);
47+
48+
// No versioning enabled
49+
$this->assertEquals('--------------------------:------------', $reflectionMethod->invokeArgs($cache, array(str_repeat('-', 12))));
50+
$this->assertLessThanOrEqual(50, strlen($reflectionMethod->invokeArgs($cache, array(str_repeat('-', 12)))));
51+
$this->assertLessThanOrEqual(50, strlen($reflectionMethod->invokeArgs($cache, array(str_repeat('-', 23)))));
52+
$this->assertLessThanOrEqual(50, strlen($reflectionMethod->invokeArgs($cache, array(str_repeat('-', 40)))));
53+
54+
$reflectionProperty = $reflectionClass->getProperty('versioningIsEnabled');
55+
$reflectionProperty->setAccessible(true);
56+
$reflectionProperty->setValue($cache, true);
57+
58+
// Versioning enabled
59+
$this->assertEquals('--------------------------:1:------------', $reflectionMethod->invokeArgs($cache, array(str_repeat('-', 12))));
60+
$this->assertLessThanOrEqual(50, strlen($reflectionMethod->invokeArgs($cache, array(str_repeat('-', 12)))));
61+
$this->assertLessThanOrEqual(50, strlen($reflectionMethod->invokeArgs($cache, array(str_repeat('-', 23)))));
62+
$this->assertLessThanOrEqual(50, strlen($reflectionMethod->invokeArgs($cache, array(str_repeat('-', 40)))));
63+
}
64+
3765
/**
3866
* @expectedException \Symfony\Component\Cache\Exception\InvalidArgumentException
3967
* @expectedExceptionMessage Namespace must be 26 chars max, 40 given ("----------------------------------------")

‎src/Symfony/Component/Cache/Traits/AbstractTrait.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Traits/AbstractTrait.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ private function getId($key)
255255
return $this->namespace.$this->namespaceVersion.$key;
256256
}
257257
if (\strlen($id = $this->namespace.$this->namespaceVersion.$key) > $this->maxIdLength) {
258-
$id = $this->namespace.$this->namespaceVersion.substr_replace(base64_encode(hash('sha256', $key, true)), ':', -22);
258+
$id = $this->namespace.$this->namespaceVersion.substr_replace(base64_encode(hash('sha256', $key, true)), ':', -(\strlen($this->namespaceVersion) + 22));
259259
}
260260

261261
return $id;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.