Skip to content

Commit

Permalink
Handle lock with long key
Browse files Browse the repository at this point in the history
  • Loading branch information
jderusse committed Jul 22, 2021
1 parent b4eb698 commit 023ad33
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Store/FlockStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private function lock(Key $key, bool $blocking)

$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), '/', '_')
);

Expand Down
21 changes: 21 additions & 0 deletions Tests/Store/FlockStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,25 @@ public function testSaveSanitizeName()

$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);
}
}

0 comments on commit 023ad33

Please sign in to comment.