8000 [Cache] fix compat with apcu < 5.1.10 by nicolas-grekas · Pull Request #44799 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Cache] fix compat with apcu < 5.1.10 #44799

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Symfony/Component/Cache/Tests/Adapter/AdapterTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion src/Symfony/Component/Cache/Traits/ApcuTrait.php
8000
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SymfonyInsight. Do we need to have here comments?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so yes, I don't want to remove that line again by mistake

$k = key($ids);
}
unset($ids[$k]);

if (null !== $v || $ok) {
$values[$k] = $v;
}
Expand Down
0