8000 bug #38126 [Cache] Limit cache version character range (lstrojny) · symfony/symfony@e8dc35d · GitHub
[go: up one dir, main page]

Skip to content

Commit e8dc35d

Browse files
bug #38126 [Cache] Limit cache version character range (lstrojny)
This PR was squashed before being merged into the 4.4 branch. Discussion ---------- [Cache] Limit cache version character range | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | n.A. | License | MIT | Doc PR | Follow up for #38108 With current HEAD in 4.4, this will fail eventually: `simple-phpunit --repeat 1000 --stop-on-failure --filter "testGetMultiple$" src/Symfony/Component/Cache/Tests/Simple/MemcachedCacheTextModeTest.php` After this PR it will no longer fail @nicolas-grekas Commits ------- 15c21db [Cache] Limit cache version character range
2 parents b4d737f + 15c21db commit e8dc35d

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/Symfony/Component/Cache/Simple/AbstractCache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ private function generateValues(iterable $values, array &$keys, $default): itera
182182
try {
183183
foreach ($values as $id => $value) {
184184
if (!isset($keys[$id])) {
185-
$id = key($keys);
185+
throw new InvalidArgumentException(sprintf('Could not match value id "%s" to keys "%s".', $id, implode('", "', $keys)));
186186
}
187187
$key = $keys[$id];
188188
unset($keys[$id]);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function clear(/*string $prefix = ''*/)
119119
}
120120
}
121121
$namespaceToClear = $this->namespace.$namespaceVersionToClear;
122-
$namespaceVersion = substr_replace(base64_encode(pack('V', mt_rand())), static::NS_SEPARATOR, 5);
122+
$namespaceVersion = strtr(substr_replace(base64_encode(pack('V', mt_rand())), static::NS_SEPARATOR, 5), '/', '_');
123123
try {
124124
$cleared = $this->doSave([static::NS_SEPARATOR.$this->namespace => $namespaceVersion], 0);
125125
} catch (\Exception $e) {
@@ -268,7 +268,7 @@ private function getId($key): string
268268
$this->namespaceVersion = $v;
269269
}
270270
if ('1'.static::NS_SEPARATOR === $this->namespaceVersion) {
271-
$this->namespaceVersion = substr_replace(base64_encode(pack('V', time())), static::NS_SEPARATOR, 5);
271+
$this->namespaceVersion = strtr(substr_replace(base64_encode(pack('V', time())), static::NS_SEPARATOR, 5), '/', '_');
272272
$this->doSave([static::NS_SEPARATOR.$this->namespace => $this->namespaceVersion], 0);
273273
}
274274
} catch (\Exception $e) {

0 commit comments

Comments
 (0)
0