From 2301b1559e3ae53a60cfd1a966d01323d1fdfee5 Mon Sep 17 00:00:00 2001 From: Bernhard Schussek Date: Fri, 18 May 2012 10:57:52 +0200 Subject: [PATCH] [Form] Tightened PropertyPath validation to reject any empty value (such as false) --- .../Component/Form/Tests/Util/PropertyPathTest.php | 10 +++++++++- src/Symfony/Component/Form/Util/PropertyPath.php | 8 ++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Form/Tests/Util/PropertyPathTest.php b/src/Symfony/Component/Form/Tests/Util/PropertyPathTest.php index 4a7190ddb1..c556df8406 100644 --- a/src/Symfony/Component/Form/Tests/Util/PropertyPathTest.php +++ b/src/Symfony/Component/Form/Tests/Util/PropertyPathTest.php @@ -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'); diff --git a/src/Symfony/Component/Form/Util/PropertyPath.php b/src/Symfony/Component/Form/Util/PropertyPath.php index 11769ff287..cfd0b07f86 100644 --- a/src/Symfony/Component/Form/Util/PropertyPath.php +++ b/src/Symfony/Component/Form/Util/PropertyPath.php @@ -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;