File tree Expand file tree Collapse file tree 5 files changed +65
-8
lines changed
src/Symfony/Component/Cache Expand file tree Collapse file tree 5 files changed +65
-8
lines changed Original file line number Diff line number Diff line change @@ -337,7 +337,9 @@ public function __destruct()
337
337
338
338
private function getId ($ key )
339
339
{
340
- return $ this ->namespace .CacheItem::validateKey ($ key );
340
+ CacheItem::validateKey ($ key );
341
+
342
+ return $ this ->namespace .$ key ;
341
343
}
342
344
343
345
private function generateItems ($ items , &$ keys )
Original file line number Diff line number Diff line change @@ -84,7 +84,9 @@ public function getItems(array $keys = array())
84
84
*/
85
85
public function hasItem ($ key )
86
86
{
87
- return isset ($ this ->expiries [CacheItem::validateKey ($ key )]) && ($ this ->expiries [$ key ] >= time () || !$ this ->deleteItem ($ key ));
87
+ CacheItem::validateKey ($ key );
88
+
89
+ return isset ($ this ->expiries [$ key ]) && ($ this ->expiries [$ key ] >= time () || !$ this ->deleteItem ($ key ));
88
90
}
89
91
90
92
/**
@@ -102,7 +104,9 @@ public function clear()
102
104
*/
103
105
public function deleteItem ($ key )
104
106
{
105
- unset($ this ->values [CacheItem::validateKey ($ key )], $ this ->expiries [$ key ]);
107
+ CacheItem::validateKey ($ key );
108
+
109
+ unset($ this ->values [$ key ], $ this ->expiries [$ key ]);
106
110
107
111
return true ;
108
112
}
Original file line number Diff line number Diff line change @@ -193,6 +193,8 @@ public function getMisses()
193
193
194
194
private function getId ($ key )
195
195
{
196
- return $ this ->namespace .CacheItem::validateKey ($ key );
196
+ CacheItem::validateKey ($ key );
197
+
198
+ return $ this ->namespace .$ key ;
197
199
}
198
200
}
Original file line number Diff line number Diff line change @@ -104,8 +104,6 @@ public function expiresAfter($time)
104
104
*
105
105
* @param string $key The key to validate.
106
106
*
107
- * @return string $key if it is valid.
108
- *
109
107
* @throws InvalidArgumentException When $key is not valid.
110
108
*/
111
109
public static function validateKey ($ key )
@@ -119,8 +117,6 @@ public static function validateKey($key)
119
117
if (isset ($ key [strcspn ($ key , '{}()/\@: ' )])) {
120
118
throw new InvalidArgumentException ('Cache key contains reserved characters {}()/\@: ' );
121
119
}
122
-
123
- return $ key ;
124
120
}
125
121
126
122
/**
Original file line number Diff line number Diff line change
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
+ namespace Symfony \Component \Cache \Tests ;
13
+
14
+ use Symfony \Component \Cache \CacheItem ;
15
+
16
+ class CacheItemTest extends \PHPUnit_Framework_TestCase
17
+ {
18
+ public function testValidKey ()
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
+ public function testInvalidKey ($ key )
29
+ {
30
+ CacheItem::validateKey ($ key );
31
+ }
32
+
33
+ public function provideInvalidKey ()
34
+ {
35
+ return array (
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
+ }
You can’t perform that action at this time.
0 commit comments