Skip to content

Commit ff25e4a

Browse files
[Cache] fix compat with apcu < 5.1.10
1 parent 9d9f27a commit ff25e4a

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/Symfony/Component/Cache/Tests/Adapter/AdapterTestCase.php

+9
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,15 @@ public function testWeirdDataMatchingMetadataWrappedValues()
296296

297297
$this->assertTrue($cache->hasItem('foobar'));
298298
}
299+
300+
public function testNullByteInKey()
301+
{
302+
$cache = $this->createCachePool(0, __FUNCTION__);
303+
304+
$cache->save($cache->getItem("a\0b")->set(123));
305+
306+
$this->assertSame(123, $cache->getItem("a\0b")->get());
307+
}
299308
}
300309

301310
class NotUnserializable

src/Symfony/Component/Cache/Traits/ApcuTrait.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,14 @@ protected function doFetch(array $ids)
5454
$unserializeCallbackHandler = ini_set('unserialize_callback_func', __CLASS__.'::handleUnserializeCallback');
5555
try {
5656
$values = [];
57-
foreach (apcu_fetch($ids, $ok) ?: [] as $k => $v) {
57+
$ids = array_flip($ids);
58+
foreach (apcu_fetch(array_keys($ids)) ?: [] as $k => $v) {
59+
if (!isset($ids[$k])) {
60+
// work around https://github.com/krakjoe/apcu/issues/247
61+
$k = key($ids);
62+
}
63+
unset($keys[$id]);
64+
5865
if (null !== $v || $ok) {
5966
$values[$k] = $v;
6067
}

0 commit comments

Comments
 (0)