diff --git a/Request/ParamFetcher.php b/Request/ParamFetcher.php index 69ac1fd77..6cf2d7d59 100644 --- a/Request/ParamFetcher.php +++ b/Request/ParamFetcher.php @@ -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', diff --git a/Tests/Request/ParamFetcherTest.php b/Tests/Request/ParamFetcherTest.php index 9e36dcb96..b783b6866 100644 --- a/Tests/Request/ParamFetcherTest.php +++ b/Tests/Request/ParamFetcherTest.php @@ -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)); } @@ -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)); } ), @@ -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)); @@ -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)); } ), @@ -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)); } ),