Skip to content

Commit a81b048

Browse files
Merge branch '3.1'
* 3.1: [Cache] Make directory hashing case insensitive
2 parents 6f58c76 + a524ba5 commit a81b048

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function process(ContainerBuilder $container)
8989

9090
private function getNamespace($namespaceSuffix, $id)
9191
{
92-
return substr(str_replace('/', '-', base64_encode(md5($id.$namespaceSuffix, true))), 0, 10);
92+
return substr(str_replace('/', '-', base64_encode(hash('sha256', $id.$namespaceSuffix, true))), 0, 10);
9393
}
9494

9595
/**

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1235,7 +1235,7 @@ private function registerPropertyInfoConfiguration(array $config, ContainerBuild
12351235

12361236
private function registerCacheConfiguration(array $config, ContainerBuilder $container)
12371237
{
1238-
$version = substr(str_replace('/', '-', base64_encode(md5(uniqid(mt_rand(), true), true))), 0, -2);
1238+
$version = substr(str_replace('/', '-', base64_encode(hash('sha256', uniqid(mt_rand(), true), true))), 0, 22);
12391239
$container->getDefinition('cache.adapter.apcu')->replaceArgument(2, $version);
12401240
$container->getDefinition('cache.adapter.system')->replaceArgument(2, $version);
12411241
$container->getDefinition('cache.adapter.filesystem')->replaceArgument(2, $config['directory']);

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/CachePoolPassTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function testNamespaceArgumentIsReplaced()
4141

4242
$this->cachePoolPass->process($container);
4343

44-
$this->assertSame('VcRIZlUhEv', $cachePool->getArgument(0));
44+
$this->assertSame('kRFqMp5odS', $cachePool->getArgument(0));
4545
}
4646

4747
public function testArgsAreReplaced()
@@ -61,7 +61,7 @@ public function testArgsAreReplaced()
6161

6262
$this->assertInstanceOf(Reference::class, $cachePool->getArgument(0));
6363
$this->assertSame('foobar', (string) $cachePool->getArgument(0));
64-
$this->assertSame('VcRIZlUhEv', $cachePool->getArgument(1));
64+
$this->assertSame('kRFqMp5odS', $cachePool->getArgument(1));
6565
$this->assertSame(3, $cachePool->getArgument(2));
6666
}
6767

src/Symfony/Component/Cache/Adapter/AbstractAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ private function getId($key)
414414
return $this->namespace.$key;
415415
}
416416
if (strlen($id = $this->namespace.$key) > $this->maxIdLength) {
417-
$id = $this->namespace.substr_replace(base64_encode(md5($key, true)), ':', -2);
417+
$id = $this->namespace.substr_replace(base64_encode(hash('sha256', $key, true)), ':', -22);
418418
}
419419

420420
return $id;

src/Symfony/Component/Cache/Adapter/FilesystemAdapterTrait.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,13 @@ private function write($file, $data, $expiresAt = null)
9898

9999
private function getFile($id, $mkdir = false)
100100
{
101-
$hash = str_replace('/', '-', base64_encode(md5(static::class.$id, true)));
102-
$dir = $this->directory.$hash[0].DIRECTORY_SEPARATOR.$hash[1].DIRECTORY_SEPARATOR;
101+
$hash = str_replace('/', '-', base64_encode(hash('sha256', static::class.$id, true)));
102+
$dir = $this->directory.strtoupper($hash[0].DIRECTORY_SEPARATOR.$hash[1].DIRECTORY_SEPARATOR);
103103

104104
if ($mkdir && !file_exists($dir)) {
105105
@mkdir($dir, 0777, true);
106106
}
107107

108-
return $dir.substr($hash, 2, -2);
108+
return $dir.substr($hash, 2, 20);
109109
}
110110
}

0 commit comments

Comments
 (0)