[Form] Tightened PropertyPath validation to reject any empty value (such as false)

This commit is contained in:
Bernhard Schussek 2012-05-18 10:57:52 +02:00
parent 7ff2a9b210
commit 2301b1559e
2 changed files with 15 additions and 3 deletions

View File

@ -449,13 +449,21 @@ class PropertyPathTest extends \PHPUnit_Framework_TestCase
}
/**
* @expectedException Symfony\Component\Form\Exception\InvalidPropertyPathException
* @expectedException Symfony\Component\Form\Exception\UnexpectedTypeException
*/
public function testInvalidPropertyPath_null()
{
new PropertyPath(null);
}
/**
* @expectedException Symfony\Component\Form\Exception\UnexpectedTypeException
*/
public function testInvalidPropertyPath_false()
{
new PropertyPath(false);
}
public function testGetParent_dot()
{
$propertyPath = new PropertyPath('grandpa.parent.child');

View File

@ -77,8 +77,12 @@ class PropertyPath implements \IteratorAggregate
*/
public function __construct($propertyPath)
{
if ('' === $propertyPath || null === $propertyPath) {
throw new InvalidPropertyPathException('The property path must not be empty');
if (!is_string($propertyPath)) {
throw new UnexpectedTypeException($propertyPath, 'string');
}
if (empty($propertyPath)) {
throw new InvalidPropertyPathException('The property path should not be empty.');
}
$this->string = (string) $propertyPath;