Skip to content

Commit 15c21db

Browse files
lstrojnynicolas-grekas
authored andcommitted
[Cache] Limit cache version character range
1 parent afd4027 commit 15c21db

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)