8000 [Form] Tightened PropertyPath validation to reject any empty value (s… · symfony/symfony@2301b15 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2301b15

Browse files
committed
[Form] Tightened PropertyPath validation to reject any empty value (such as false)
1 parent 7ff2a9b commit 2301b15

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/Symfony/Component/Form/Tests/Util/PropertyPathTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,13 +449,21 @@ public function testInvalidPropertyPath_empty()
449449
}
450450

451451
/**
452-
* @expectedException Symfony\Component\Form\Exception\InvalidPropertyPathException
452+
* @expectedException Symfony\Component\Form\Exception\UnexpectedTypeException
453453
*/
454454
public function testInvalidPropertyPath_null()
455455
{
456456
new PropertyPath(null);
457457
}
458458

459+
/**
460+
* @expectedException Symfony\Component\Form\Exception\UnexpectedTypeException
461+
*/
462+
public function testInvalidPropertyPath_false()
463+
{
464+
new PropertyPath(false);
465+
}
466+
459467
public function testGetParent_dot()
460468
{
461469
$propertyPath = new PropertyPath('grandpa.parent.child');

src/Symfony/Component/Form/Util/PropertyPath.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,12 @@ class PropertyPath implements \IteratorAggregate
7777
*/
7878
public function __construct($propertyPath)
7979
{
80-
if ('' === $propertyPath || null === $propertyPath) {
81-
throw new InvalidPropertyPathException('The property path must not be empty');
80+
if (!is_string($propertyPath)) {
81+
throw new UnexpectedTypeException($propertyPath, 'string');
82+
}
83+
84+
if (empty($propertyPath)) {
85+
throw new InvalidPropertyPathException('The property path should not be empty.');
8286
}
8387

8488
$this->string = (string) $propertyPath;

0 commit comments

Comments
 (0)
0