Skip to content

Commit 05ef409

Browse files
committed
minor #23766 Consistently use 7 chars of sha256 for hash-based id generation (nicolas-grekas)
This PR was merged into the 3.4 branch. Discussion ---------- Consistently use 7 chars of sha256 for hash-based id generation | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - This prevents generating over long service ids, and for filesystem-related changes, makes the Windows 258 chars limit farther. Commits ------- bc22cdd034 Consistently use 7 chars of sha256 for hash-based id generation
2 parents 5372b4d + cefc3dd commit 05ef409

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

Store/FlockStore.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ private function lock(Key $key, $blocking)
7171
$fileName = sprintf('%s/sf.%s.%s.lock',
7272
$this->lockPath,
7373
preg_replace('/[^a-z0-9\._-]+/i', '-', $key),
74-
hash('sha256', $key)
74+
strtr(substr(base64_encode(hash('sha256', $key, true)), 0, 7), '/', '_')
7575
);
7676

7777
// Silence error reporting

Tests/Store/FlockStoreTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ public function testSaveSanitizeName()
6262
$key = new Key('<?php echo "% hello word ! %" ?>');
6363

6464
$file = sprintf(
65-
'%s/sf.-php-echo-hello-word-.4b3d9d0d27ddef3a78a64685dda3a963e478659a9e5240feaf7b4173a8f28d5f.lock',
66-
sys_get_temp_dir()
65+
'%s/sf.-php-echo-hello-word-.%s.lock',
66+
sys_get_temp_dir(),
67+
strtr(substr(base64_encode(hash('sha256', $key, true)), 0, 7), '/', '_')
6768
);
6869
// ensure the file does not exist before the store
6970
@unlink($file);

0 commit comments

Comments
 (0)