8000 bug #20453 [Cache] Make directory hashing case insensitive (nicolas-g… · symfony/symfony@a524ba5 · GitHub
[go: up one dir, main page]

Skip to content

Commit a524ba5

Browse files
committed
bug #20453 [Cache] Make directory hashing case insensitive (nicolas-grekas)
This PR was merged into the 3.1 branch. Discussion ---------- [Cache] Make directory hashing case insensitive | Q | A | ------------- | --- | Branch? | 3.1 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #20450 | License | MIT | Doc PR | - Fixes this situation: a Windows OS, running a Debian via VirtualBox and Vagrant. So the cache folder is on a Windows partition while the PHP command is running inside Debian... Not testable without this specific setup... Commits ------- 6d4a658 [Cache] Make directory hashing case insensitive
2 parents 790e7dd + 6d4a658 commit a524ba5

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

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

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

8585
private function getNamespace($namespaceSuffix, $id)
8686
{
87-
return substr(str_replace('/', '-', base64_encode(md5($id.$namespaceSuffix, true))), 0, 10);
87+
return substr(str_replace('/', '-', base64_encode(hash('sha256', $id.$namespaceSuffix, true))), 0, 10);
8888
}
8989

9090
/**

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

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

10381038
private function registerCacheConfiguration(array $config, ContainerBuilder $container)
10391039
{
1040-
$version = substr(str_replace('/', '-', base64_encode(md5(uniqid(mt_rand(), true), true))), 0, -2);
1040+
$version = substr(str_replace('/', '-', base64_encode(hash('sha256', uniqid(mt_rand(), true), true))), 0, 22);
10411041
$container->getDefinition('cache.adapter.apcu')->replaceArgument(2, $version);
10421042
$container->getDefinition('cache.adapter.system')->replaceArgument(2, $version);
10431043
$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/FilesystemAdapter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,13 @@ protected function doSave(array $values, $lifetime)
146146

147147
private function getFile($id, $mkdir = false)
148148
{
149-
$hash = str_replace('/', '-', base64_encode(md5($id, true)));
150-
$dir = $this->directory.$hash[0].DIRECTORY_SEPARATOR.$hash[1].DIRECTORY_SEPARATOR;
149+
$hash = str_replace('/', '-', base64_encode(hash('sha256', $id, true)));
150+
$dir = $this->directory.strtoupper($hash[0].DIRECTORY_SEPARATOR.$hash[1].DIRECTORY_SEPARATOR);
151151

152152
if ($mkdir && !file_exists($dir)) {
153153
@mkdir($dir, 0777, true);
154154
}
155155

156-
return $dir.substr($hash, 2, -2);
156+
return $dir.substr($hash, 2, 20);
157157
}
158158
}

0 commit comments

Comments
 (0)
0