Skip to content

Commit 9c3345f

Browse files
committed
feature #33516 [Cache] Added reserved characters constant for CacheItem (andyexeter)
This PR was squashed before being merged into the 4.4 branch (closes #33516). Discussion ---------- [Cache] Added reserved characters constant for CacheItem | Q | A | ------------- | --- | Branch? | 4.4 <!-- see below --> | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | N/A <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | N/A <!-- required for new features --> This PR introduces a `RESERVED_CHARACTERS` constant to the `CacheItem` class to keep things DRY. The rationale for making the constant public is so that developers can access the list of reserved characters so they could - for example - sanitise keys before passing them to the Cache component. Commits ------- d853306 [Cache] Added reserved characters constant for CacheItem
2 parents 419be6a + d853306 commit 9c3345f

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

src/Symfony/Component/Cache/CacheItem.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ public function tag($tags): ItemInterface
129129
if ('' === $tag) {
130130
throw new InvalidArgumentException('Cache tag length must be greater than zero');
131131
}
132-
if (false !== strpbrk($tag, '{}()/\@:')) {
133-
throw new InvalidArgumentException(sprintf('Cache tag "%s" contains reserved characters {}()/\@:', $tag));
132+
if (false !== strpbrk($tag, self::RESERVED_CHARACTERS)) {
133+
throw new InvalidArgumentException(sprintf('Cache tag "%s" contains reserved characters %s', $tag, self::RESERVED_CHARACTERS));
134134
}
135135
$this->newMetadata[self::METADATA_TAGS][$tag] = $tag;
136136
}
@@ -173,8 +173,8 @@ public static function validateKey($key): string
173173
if ('' === $key) {
174174
throw new InvalidArgumentException('Cache key length must be greater than zero');
175175
}
176-
if (false !== strpbrk($key, '{}()/\@:')) {
177-
throw new InvalidArgumentException(sprintf('Cache key "%s" contains reserved characters {}()/\@:', $key));
176+
if (false !== strpbrk($key, self::RESERVED_CHARACTERS)) {
177+
throw new InvalidArgumentException(sprintf('Cache key "%s" contains reserved characters %s', $key, self::RESERVED_CHARACTERS));
178178
}
179179

180180
return $key;

src/Symfony/Component/Cache/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"php": "^7.1.3",
2525
"psr/cache": "~1.0",
2626
"psr/log": "~1.0",
27-
"symfony/cache-contracts": "^1.1|^2",
27+
"symfony/cache-contracts": "^1.1.7|^2",
2828
"symfony/service-contracts": "^1.1|^2",
2929
"symfony/var-exporter": "^4.2|^5.0"
3030
},

src/Symfony/Contracts/Cache/ItemInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ interface ItemInterface extends CacheItemInterface
3737
*/
3838
const METADATA_TAGS = 'tags';
3939

40+
/**
41+
* Reserved characters that cannot be used in a key or tag.
42+
*/
43+
const RESERVED_CHARACTERS = '{}()/\@:';
44+
4045
/**
4146
* Adds a tag to a cache item.
4247
*

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