From be88fd00f80283464d6edf14ed04c9e9b6a8ff70 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 28 Mar 2023 16:39:01 +0200 Subject: [PATCH] [Cache] Fix storing binary keys when using pgsql --- .../Cache/Adapter/DoctrineDbalAdapter.php | 16 ++++++++++++++++ .../Component/Cache/Adapter/PdoAdapter.php | 16 ++++++++++++++++ .../Cache/Traits/AbstractAdapterTrait.php | 5 ++++- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Cache/Adapter/DoctrineDbalAdapter.php b/src/Symfony/Component/Cache/Adapter/DoctrineDbalAdapter.php index 73f0ea6bcc480..16a0691cb2b42 100644 --- a/src/Symfony/Component/Cache/Adapter/DoctrineDbalAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/DoctrineDbalAdapter.php @@ -334,6 +334,22 @@ protected function doSave(array $values, int $lifetime) return $failed; } + /** + * @internal + */ + protected function getId($key) + { + if ('pgsql' !== $this->platformName ??= $this->getPlatformName()) { + return parent::getId($key); + } + + if (str_contains($key, "\0") || str_contains($key, '%') || !preg_match('//u', $key)) { + $key = rawurlencode($key); + } + + return parent::getId($key); + } + private function getPlatformName(): string { if (isset($this->platformName)) { diff --git a/src/Symfony/Component/Cache/Adapter/PdoAdapter.php b/src/Symfony/Component/Cache/Adapter/PdoAdapter.php index 5d107244312e7..34a0c12190700 100644 --- a/src/Symfony/Component/Cache/Adapter/PdoAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/PdoAdapter.php @@ -559,6 +559,22 @@ protected function doSave(array $values, int $lifetime) return $failed; } + /** + * @internal + */ + protected function getId($key) + { + if ('pgsql' !== $this->driver ?? ($this->getConnection() ? $this->driver : null)) { + return parent::getId($key); + } + + if (str_contains($key, "\0") || str_contains($key, '%') || !preg_match('//u', $key)) { + $key = rawurlencode($key); + } + + return parent::getId($key); + } + private function getConnection(): \PDO { if (null === $this->conn) { diff --git a/src/Symfony/Component/Cache/Traits/AbstractAdapterTrait.php b/src/Symfony/Component/Cache/Traits/AbstractAdapterTrait.php index c1a850877ff3d..32d78b1858cff 100644 --- a/src/Symfony/Component/Cache/Traits/AbstractAdapterTrait.php +++ b/src/Symfony/Component/Cache/Traits/AbstractAdapterTrait.php @@ -365,7 +365,10 @@ private function generateItems(iterable $items, array &$keys): \Generator } } - private function getId($key) + /** + * @internal + */ + protected function getId($key) { if ($this->versioningIsEnabled && '' === $this->namespaceVersion) { $this->ids = []; 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