Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc4acbb4

Browse files
minor#18604 [Cache] Test & tweak CacheItem::validateKey() (nicolas-grekas)
This PR was merged into the 3.1-dev branch.Discussion----------[Cache] Test & tweak CacheItem::validateKey()| Q | A| ------------- | ---| Branch? | 3.1| Bug fix? | no| New feature? | no| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets | -| License | MIT| Doc PR | -Ping@javiereguiluz@stofCommits-------4256add [Cache] Test & tweak CacheItem::validateKey()
2 parents357785a +4256add commitc4acbb4

File tree

5 files changed

+65
-8
lines changed

5 files changed

+65
-8
lines changed

‎src/Symfony/Component/Cache/Adapter/AbstractAdapter.php‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,9 @@ public function __destruct()
337337

338338
privatefunctiongetId($key)
339339
{
340-
return$this->namespace.CacheItem::validateKey($key);
340+
CacheItem::validateKey($key);
341+
342+
return$this->namespace.$key;
341343
}
342344

343345
privatefunctiongenerateItems($items, &$keys)

‎src/Symfony/Component/Cache/Adapter/ArrayAdapter.php‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ public function getItems(array $keys = array())
8484
*/
8585
publicfunctionhasItem($key)
8686
{
87-
returnisset($this->expiries[CacheItem::validateKey($key)]) && ($this->expiries[$key] >=time() || !$this->deleteItem($key));
87+
CacheItem::validateKey($key);
88+
89+
returnisset($this->expiries[$key]) && ($this->expiries[$key] >=time() || !$this->deleteItem($key));
8890
}
8991

9092
/**
@@ -102,7 +104,9 @@ public function clear()
102104
*/
103105
publicfunctiondeleteItem($key)
104106
{
105-
unset($this->values[CacheItem::validateKey($key)],$this->expiries[$key]);
107+
CacheItem::validateKey($key);
108+
109+
unset($this->values[$key],$this->expiries[$key]);
106110

107111
returntrue;
108112
}

‎src/Symfony/Component/Cache/Adapter/ProxyAdapter.php‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ public function getMisses()
193193

194194
privatefunctiongetId($key)
195195
{
196-
return$this->namespace.CacheItem::validateKey($key);
196+
CacheItem::validateKey($key);
197+
198+
return$this->namespace.$key;
197199
}
198200
}

‎src/Symfony/Component/Cache/CacheItem.php‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,6 @@ public function expiresAfter($time)
104104
*
105105
* @param string $key The key to validate.
106106
*
107-
* @return string $key if it is valid.
108-
*
109107
* @throws InvalidArgumentException When $key is not valid.
110108
*/
111109
publicstaticfunctionvalidateKey($key)
@@ -119,8 +117,6 @@ public static function validateKey($key)
119117
if (isset($key[strcspn($key,'{}()/\@:')])) {
120118
thrownewInvalidArgumentException('Cache key contains reserved characters {}()/\@:');
121119
}
122-
123-
return$key;
124120
}
125121

126122
/**
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\Cache\Tests;
13+
14+
useSymfony\Component\Cache\CacheItem;
15+
16+
class CacheItemTestextends \PHPUnit_Framework_TestCase
17+
{
18+
publicfunctiontestValidKey()
19+
{
20+
$this->assertNull(CacheItem::validateKey('foo'));
21+
}
22+
23+
/**
24+
* @dataProvider provideInvalidKey
25+
* @expectedException Symfony\Component\Cache\Exception\InvalidArgumentException
26+
* @expectedExceptionMessage Cache key
27+
*/
28+
publicfunctiontestInvalidKey($key)
29+
{
30+
CacheItem::validateKey($key);
31+
}
32+
33+
publicfunctionprovideInvalidKey()
34+
{
35+
returnarray(
36+
array(''),
37+
array('{'),
38+
array('}'),
39+
array('('),
40+
array(')'),
41+
array('/'),
42+
array('\\'),
43+
array('@'),
44+
array(':'),
45+
array(true),
46+
array(null),
47+
array(1),
48+
array(1.1),
49+
array(array()),
50+
array(new \Exception('foo')),
51+
);
52+
}
53+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp