Skip to content

Commit 2794527

Browse files
committed
bug #49848 [Cache] Fix storing binary keys when using pgsql (nicolas-grekas)
This PR was merged into the 5.4 branch. Discussion ---------- [Cache] Fix storing binary keys when using pgsql | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #49748 | License | MIT | Doc PR | - Commits ------- be88fd0 [Cache] Fix storing binary keys when using pgsql
2 parents 2ed1fef + be88fd0 commit 2794527

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

src/Symfony/Component/Cache/Adapter/DoctrineDbalAdapter.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,22 @@ protected function doSave(array $values, int $lifetime)
334334
return $failed;
335335
}
336336

337+
/**
338+
* @internal
339+
*/
340+
protected function getId($key)
341+
{
342+
if ('pgsql' !== $this->platformName ??= $this->getPlatformName()) {
343+
return parent::getId($key);
344+
}
345+
346+
if (str_contains($key, "\0") || str_contains($key, '%') || !preg_match('//u', $key)) {
347+
$key = rawurlencode($key);
348+
}
349+
350+
return parent::getId($key);
351+
}
352+
337353
private function getPlatformName(): string
338354
{
339355
if (isset($this->platformName)) {

src/Symfony/Component/Cache/Adapter/PdoAdapter.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,22 @@ protected function doSave(array $values, int $lifetime)
559559
return $failed;
560560
}
561561

562+
/**
563+
* @internal
564+
*/
565+
protected function getId($key)
566+
{
567+
if ('pgsql' !== $this->driver ?? ($this->getConnection() ? $this->driver : null)) {
568+
return parent::getId($key);
569+
}
570+
571+
if (str_contains($key, "\0") || str_contains($key, '%') || !preg_match('//u', $key)) {
572+
$key = rawurlencode($key);
573+
}
574+
575+
return parent::getId($key);
576+
}
577+
562578
private function getConnection(): \PDO
563579
{
564580
if (null === $this->conn) {

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,10 @@ private function generateItems(iterable $items, array &$keys): \Generator
365365
}
366366
}
367367

368-
private function getId($key)
368+
/**
369+
* @internal
370+
*/
371+
protected function getId($key)
369372
{
370373
if ($this->versioningIsEnabled && '' === $this->namespaceVersion) {
371374
$this->ids = [];

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy