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 https://github.com/symfony/symfony/pull/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
-------

15c21db856 [Cache] Limit cache version character range
This commit is contained in:
Nicolas Grekas 2020-09-10 18:48:32 +02:00
commit e8dc35dc2d
2 changed files with 3 additions and 3 deletions

View File

@ -182,7 +182,7 @@ abstract class AbstractCache implements Psr16CacheInterface, LoggerAwareInterfac
try {
foreach ($values as $id => $value) {
if (!isset($keys[$id])) {
$id = key($keys);
throw new InvalidArgumentException(sprintf('Could not match value id "%s" to keys "%s".', $id, implode('", "', $keys)));
}
$key = $keys[$id];
unset($keys[$id]);

View File

@ -119,7 +119,7 @@ trait AbstractTrait
}
}
$namespaceToClear = $this->namespace.$namespaceVersionToClear;
$namespaceVersion = substr_replace(base64_encode(pack('V', mt_rand())), static::NS_SEPARATOR, 5);
$namespaceVersion = strtr(substr_replace(base64_encode(pack('V', mt_rand())), static::NS_SEPARATOR, 5), '/', '_');
try {
$cleared = $this->doSave([static::NS_SEPARATOR.$this->namespace => $namespaceVersion], 0);
} catch (\Exception $e) {
@ -268,7 +268,7 @@ trait AbstractTrait
$this->namespaceVersion = $v;
}
if ('1'.static::NS_SEPARATOR === $this->namespaceVersion) {
$this->namespaceVersion = substr_replace(base64_encode(pack('V', time())), static::NS_SEPARATOR, 5);
$this->namespaceVersion = strtr(substr_replace(base64_encode(pack('V', time())), static::NS_SEPARATOR, 5), '/', '_');
$this->doSave([static::NS_SEPARATOR.$this->namespace => $this->namespaceVersion], 0);
}
} catch (\Exception $e) {