8000 added some validation · symfony/symfony@6fc1cc3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6fc1cc3

Browse files
committed
added some validation
1 parent c11a8eb commit 6fc1cc3

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

src/Symfony/Bridge/Monolog/Handler/FingersCrossed/HttpCodeActivationStrategy.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,20 @@ class HttpCodeActivationStrategy extends ErrorLevelActivationStrategy
2525
private $exclusions;
2626
private $requestStack;
2727

28+
/**
29+
* @param array $exclusions each exclusion must have a "code" and "urls" keys
30+
*/
2831
public function __construct(RequestStack $requestStack, array $exclusions, $actionLevel)
2932
{
33+
foreach ($exclusions as $exclusion) {
34+
if (!array_key_exists('code', $exclusion)) {
35+
throw new \LogicException(sprintf('An exclusion must have a "code" key'));
36+
}
37+
if (!array_key_exists('urls', $exclusion)) {
38+
throw new \LogicException(sprintf('An exclusion must have a "urls" key'));
39+
}
40+
}
41+
3042
parent::__construct($actionLevel);
3143

3244
$this->requestStack = $requestStack;
@@ -49,8 +61,8 @@ public function isHandlerActivated(array $record)
4961
}
5062

5163
$urlBlacklist = null;
52-
if (count($exclusion['url'])) {
53-
return !preg_match('{('.implode('|', $exclusion['url']).')}i', $request->getPathInfo());
64+
if (count($exclusion['urls'])) {
65+
return !preg_match('{('.implode('|', $exclusion['urls']).')}i', $request->getPathInfo());
5466
}
5567

5668
return false;

src/Symfony/Bridge/Monolog/Tests/Handler/FingersCrossed/HttpCodeActivationStrategyTest.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,22 @@
2020

2121
class HttpCodeActivationStrategyTest extends TestCase
2222
{
23+
/**
24+
* @expectedException \LogicException
25+
*/
26+
public function testExclusionsWithoutCode()
27+
{
28+
new HttpCodeActivationStrategy(new RequestStack(), array(array('urls' => array())), Logger::WARNING);
29+
}
30+
31+
/**
32+
* @expectedException \LogicException
33+
*/
34+
public function testExclusionsWithoutUrls()
35+
{
36+
new HttpCodeActivationStrategy(new RequestStack(), array(array('code' => 404)), Logger::WARNING);
37+
}
38+
2339
/**
2440
* @dataProvider isActivatedProvider
2541
*/
@@ -31,10 +47,10 @@ public function testIsActivated($url, $record, $expected)
3147
$strategy = new HttpCodeActivationStrategy(
3248
$requestStack,
3349
array(
34-
array('code' => 403, 'url' => array()),
35-
array('code' => 404, 'url' => array()),
36-
array('code' => 405, 'url' => array()),
37-
array('code' => 400, 'url' => array('^/400/a', '^/400/b')),
50+
array('code' => 403, 'urls' => array()),
51+
array('code' => 404, 'urls' => array()),
52+
array('code' => 405, 'urls' => array()),
53+
array('code' => 400, 'urls' => array('^/400/a', '^/400/b')),
3854
),
3955
Logger::WARNING
4056
);

0 commit comments

Comments
 (0)
0