Handle lock with long key

This commit is contained in:
Jérémy Derussé 2021-07-21 11:54:21 +02:00
parent 154f7e9839
commit f82682424e
No known key found for this signature in database
GPG Key ID: 2083FA5758C473D2
2 changed files with 22 additions and 1 deletions

View File

@ -74,7 +74,7 @@ class FlockStore implements StoreInterface, BlockingStoreInterface
$fileName = sprintf('%s/sf.%s.%s.lock',
$this->lockPath,
preg_replace('/[^a-z0-9\._-]+/i', '-', $key),
substr(preg_replace('/[^a-z0-9\._-]+/i', '-', $key), 0, 50),
strtr(substr(base64_encode(hash('sha256', $key, true)), 0, 7), '/', '_')
);

View File

@ -73,4 +73,25 @@ class FlockStoreTest extends AbstractStoreTest
$store->delete($key);
}
public function testSaveSanitizeLongName()
{
$store = $this->getStore();
$key = new Key(str_repeat(__CLASS__, 100));
$file = sprintf(
'%s/sf.Symfony-Component-Lock-Tests-Store-FlockStoreTestS.%s.lock',
sys_get_temp_dir(),
strtr(substr(base64_encode(hash('sha256', $key, true)), 0, 7), '/', '_')
);
// ensure the file does not exist before the store
@unlink($file);
$store->save($key);
$this->assertFileExists($file);
$store->delete($key);
}
}