Skip to content

Commit

Permalink
fix bug introduced in the QueryParam validation of regexp's in #700
Browse files Browse the repository at this point in the history
  • Loading branch information
lsmith77 committed Mar 11, 2014
1 parent 13bcb1d commit ed28a05
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Request/ParamFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public function cleanParamWithRequirements(Param $config, $param, $strict)
}

$constraint = new Regex(array(
'pattern' => '#^'.preg_quote($config->requirements).'$#xsu',
'pattern' => '#^'.$config->requirements.'$#xsu',
'message' => sprintf(
"%s parameter value '%s', does not match requirements '%s'",
$config instanceof QueryParam ? 'Query' : 'Request',
Expand Down
24 changes: 17 additions & 7 deletions Tests/Request/ParamFetcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@ function(\PHPUnit_Framework_MockObject_MockObject $validator, \PHPUnit_Framework

$validator->expects($self->at(0))
->method('validateValue')
->with('bar', new Regex(array('pattern' => '#^\\\d\+$#xsu', 'message' => "Query parameter value 'bar', does not match requirements '\\d+'")), null)
->with('bar', new Regex(array('pattern' => '#^\\d+$#xsu', 'message' => "Query parameter value 'bar', does not match requirements '\\d+'")), null)
->will($self->returnValue($errors));
$validator->expects($self->at(1))
->method('validateValue')
->with('bar', new Regex(array('pattern' => '#^\\\d\+$#xsu', 'message' => "Query parameter value 'bar', does not match requirements '\\d+'")), null)
->with('bar', new Regex(array('pattern' => '#^\\d+$#xsu', 'message' => "Query parameter value 'bar', does not match requirements '\\d+'")), null)
->will($self->returnValue($errors));

}
Expand Down Expand Up @@ -236,12 +236,12 @@ function(\PHPUnit_Framework_MockObject_MockObject $validator, \PHPUnit_Framework

$validator->expects($self->at(1))
->method('validateValue')
->with('invaliddata', new Regex(array('pattern' => '#^\\\d\+$#xsu', 'message' => "Query parameter value 'invaliddata', does not match requirements '\\d+'")), null)
->with('invaliddata', new Regex(array('pattern' => '#^\\d+$#xsu', 'message' => "Query parameter value 'invaliddata', does not match requirements '\\d+'")), null)
->will($self->returnValue($errors));

$validator->expects($self->at(6))
->method('validateValue')
->with('invaliddata', new Regex(array('pattern' => '#^\\\d\+$#xsu', 'message' => "Query parameter value 'invaliddata', does not match requirements '\\d+'")), null)
->with('invaliddata', new Regex(array('pattern' => '#^\\d+$#xsu', 'message' => "Query parameter value 'invaliddata', does not match requirements '\\d+'")), null)
->will($self->returnValue($errors));
}
),
Expand Down Expand Up @@ -285,6 +285,16 @@ function(\PHPUnit_Framework_MockObject_MockObject $validator, \PHPUnit_Framework

public function testValidatesConfiguredParamStrictly()
{
$constraint = new Regex(array(
'pattern' => '#^\d+$#xsu',
'message' => "Query parameter value '354', does not match requirements '\\d+'"
));

$this->validator->expects($this->once())
->method('validateValue')
->with('354', $constraint)
;

$queryFetcher = $this->getParamFetcher(array('boozz' => 354), array());
$queryFetcher->setController($this->controller);
$this->assertEquals(354, $queryFetcher->get('boozz', true));
Expand Down Expand Up @@ -355,12 +365,12 @@ function(\PHPUnit_Framework_MockObject_MockObject $validator, \PHPUnit_Framework

$validator->expects($self->at(0))
->method('validateValue')
->with('foo', new Regex(array('pattern' => '#^\\\d\+$#xsu', 'message' => "Request parameter value 'foo', does not match requirements '\\d+'")), null)
->with('foo', new Regex(array('pattern' => '#^\\d+$#xsu', 'message' => "Request parameter value 'foo', does not match requirements '\\d+'")), null)
->will($self->returnValue($errors));

$validator->expects($self->at(1))
->method('validateValue')
->with('foo', new Regex(array('pattern' => '#^\\\d\+$#xsu', 'message' => "Request parameter value 'foo', does not match requirements '\\d+'")), null)
->with('foo', new Regex(array('pattern' => '#^\\d+$#xsu', 'message' => "Request parameter value 'foo', does not match requirements '\\d+'")), null)
->will($self->returnValue($errors));
}
),
Expand All @@ -375,7 +385,7 @@ function(\PHPUnit_Framework_MockObject_MockObject $validator, \PHPUnit_Framework

$validator->expects($self->at(0))
->method('validateValue')
->with('foo', new Regex(array('pattern' => '#^\\\d\?$#xsu', 'message' => "Request parameter value 'foo', does not match requirements '\\d?'")), null)
->with('foo', new Regex(array('pattern' => '#^\\d?$#xsu', 'message' => "Request parameter value 'foo', does not match requirements '\\d?'")), null)
->will($self->returnValue($errors));
}
),
Expand Down

0 comments on commit ed28a05

Please sign in to comment.