Skip to content

Commit 023ad33

Browse files
committed
Handle lock with long key
1 parent b4eb698 commit 023ad33

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

Store/FlockStore.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ private function lock(Key $key, bool $blocking)
7474

7575
$fileName = sprintf('%s/sf.%s.%s.lock',
7676
$this->lockPath,
77-
preg_replace('/[^a-z0-9\._-]+/i', '-', $key),
77+
substr(preg_replace('/[^a-z0-9\._-]+/i', '-', $key), 0, 50),
7878
strtr(substr(base64_encode(hash('sha256', $key, true)), 0, 7), '/', '_')
7979
);
8080

Tests/Store/FlockStoreTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,25 @@ public function testSaveSanitizeName()
7373

7474
$store->delete($key);
7575
}
76+
77+
public function testSaveSanitizeLongName()
78+
{
79+
$store = $this->getStore();
80+
81+
$key = new Key(str_repeat(__CLASS__, 100));
82+
83+
$file = sprintf(
84+
'%s/sf.Symfony-Component-Lock-Tests-Store-FlockStoreTestS.%s.lock',
85+
sys_get_temp_dir(),
86+
strtr(substr(base64_encode(hash('sha256', $key, true)), 0, 7), '/', '_')
87+
);
88+
// ensure the file does not exist before the store
89+
@unlink($file);
90+
91+
$store->save($key);
92+
93+
$this->assertFileExists($file);
94+
95+
$store->delete($key);
96+
}
7697
}

0 commit comments

Comments
 (0)