Skip to content

Commit 9d14648

Browse files
feat(cache): Replace unauthorized chars in cache key by _
1 parent 8a36a9e commit 9d14648

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/AbstractCache.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,17 +145,24 @@ protected function getCacheKey(string $scope, string $value): string
145145
if (!isset($this->cacheKeys[$scope][$value])) {
146146
switch ($scope) {
147147
case Constants::SCOPE_RANGE:
148-
$this->cacheKeys[$scope][$value] = Constants::SCOPE_IP . self::CACHE_SEP . $value;
148+
$result = Constants::SCOPE_IP . self::CACHE_SEP . $value;
149149
break;
150150
case Constants::SCOPE_IP:
151151
case Constants::CACHE_TAG_GEO . self::CACHE_SEP . Constants::SCOPE_IP:
152152
case Constants::CACHE_TAG_CAPTCHA . self::CACHE_SEP . Constants::SCOPE_IP:
153153
case Constants::SCOPE_COUNTRY:
154-
$this->cacheKeys[$scope][$value] = $scope . self::CACHE_SEP . $value;
154+
$result = $scope . self::CACHE_SEP . $value;
155155
break;
156156
default:
157157
throw new BouncerException('Unknown scope:' . $scope);
158158
}
159+
160+
/**
161+
* Replace unauthorized symbols.
162+
*
163+
* @see https://symfony.com/doc/current/components/cache/cache_items.html#cache-item-keys-and-values
164+
*/
165+
$this->cacheKeys[$scope][$value] = preg_replace('/[^A-Za-z0-9_.]/', self::CACHE_SEP, $result);
159166
}
160167

161168
return $this->cacheKeys[$scope][$value];

0 commit comments

Comments
 (0)