From d8533066deebb3c36d7b9149bce09563c70ce285 Mon Sep 17 00:00:00 2001 From: andyexeter Date: Mon, 9 Sep 2019 12:19:12 +0100 Subject: [PATCH] [Cache] Added reserved characters constant for CacheItem --- src/Symfony/Component/Cache/CacheItem.php | 8 ++++---- src/Symfony/Component/Cache/composer.json | 2 +- src/Symfony/Contracts/Cache/ItemInterface.php | 5 +++++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Component/Cache/CacheItem.php b/src/Symfony/Component/Cache/CacheItem.php index c41c045925..3abd50e0a4 100644 --- a/src/Symfony/Component/Cache/CacheItem.php +++ b/src/Symfony/Component/Cache/CacheItem.php @@ -129,8 +129,8 @@ final class CacheItem implements ItemInterface if ('' === $tag) { throw new InvalidArgumentException('Cache tag length must be greater than zero'); } - if (false !== strpbrk($tag, '{}()/\@:')) { - throw new InvalidArgumentException(sprintf('Cache tag "%s" contains reserved characters {}()/\@:', $tag)); + if (false !== strpbrk($tag, self::RESERVED_CHARACTERS)) { + throw new InvalidArgumentException(sprintf('Cache tag "%s" contains reserved characters %s', $tag, self::RESERVED_CHARACTERS)); } $this->newMetadata[self::METADATA_TAGS][$tag] = $tag; } @@ -173,8 +173,8 @@ final class CacheItem implements ItemInterface if ('' === $key) { throw new InvalidArgumentException('Cache key length must be greater than zero'); } - if (false !== strpbrk($key, '{}()/\@:')) { - throw new InvalidArgumentException(sprintf('Cache key "%s" contains reserved characters {}()/\@:', $key)); + if (false !== strpbrk($key, self::RESERVED_CHARACTERS)) { + throw new InvalidArgumentException(sprintf('Cache key "%s" contains reserved characters %s', $key, self::RESERVED_CHARACTERS)); } return $key; diff --git a/src/Symfony/Component/Cache/composer.json b/src/Symfony/Component/Cache/composer.json index ab9513ea05..83aecc0d48 100644 --- a/src/Symfony/Component/Cache/composer.json +++ b/src/Symfony/Component/Cache/composer.json @@ -24,7 +24,7 @@ "php": "^7.1.3", "psr/cache": "~1.0", "psr/log": "~1.0", - "symfony/cache-contracts": "^1.1|^2", + "symfony/cache-contracts": "^1.1.7|^2", "symfony/service-contracts": "^1.1|^2", "symfony/var-exporter": "^4.2|^5.0" }, diff --git a/src/Symfony/Contracts/Cache/ItemInterface.php b/src/Symfony/Contracts/Cache/ItemInterface.php index 4884a2fffe..cbd72260ba 100644 --- a/src/Symfony/Contracts/Cache/ItemInterface.php +++ b/src/Symfony/Contracts/Cache/ItemInterface.php @@ -37,6 +37,11 @@ interface ItemInterface extends CacheItemInterface */ const METADATA_TAGS = 'tags'; + /** + * Reserved characters that cannot be used in a key or tag. + */ + const RESERVED_CHARACTERS = '{}()/\@:'; + /** * Adds a tag to a cache item. *