diff --git a/src/Symfony/Component/Cache/Tests/Adapter/AdapterTestCase.php b/src/Symfony/Component/Cache/Tests/Adapter/AdapterTestCase.php index a72ae663f09d6..123cda89b8728 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/AdapterTestCase.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/AdapterTestCase.php @@ -296,6 +296,15 @@ public function testWeirdDataMatchingMetadataWrappedValues() $this->assertTrue($cache->hasItem('foobar')); } + + public function testNullByteInKey() + { + $cache = $this->createCachePool(0, __FUNCTION__); + + $cache->save($cache->getItem("a\0b")->set(123)); + + $this->assertSame(123, $cache->getItem("a\0b")->get()); + } } class NotUnserializable diff --git a/src/Symfony/Component/Cache/Traits/ApcuTrait.php b/src/Symfony/Component/Cache/Traits/ApcuTrait.php index b56ae4f7c39ac..ace28c7d37bd8 100644 --- a/src/Symfony/Component/Cache/Traits/ApcuTrait.php +++ b/src/Symfony/Component/Cache/Traits/ApcuTrait.php @@ -54,7 +54,14 @@ protected function doFetch(array $ids) $unserializeCallbackHandler = ini_set('unserialize_callback_func', __CLASS__.'::handleUnserializeCallback'); try { $values = []; - foreach (apcu_fetch($ids, $ok) ?: [] as $k => $v) { + $ids = array_flip($ids); + foreach (apcu_fetch(array_keys($ids), $ok) ?: [] as $k => $v) { + if (!isset($ids[$k])) { + // work around https://github.com/krakjoe/apcu/issues/247 + $k = key($ids); + } + unset($ids[$k]); + if (null !== $v || $ok) { $values[$k] = $v; }