[DomCrawler] Fixed a fatal error when setting a value in a malformed field name.
This commit is contained in:
parent
18f55ffe5e
commit
bce6bd2858
@ -204,8 +204,12 @@ class FormFieldRegistry
|
|||||||
{
|
{
|
||||||
if (preg_match('/^(?P<base>[^[]+)(?P<extra>(\[.*)|$)/', $name, $m)) {
|
if (preg_match('/^(?P<base>[^[]+)(?P<extra>(\[.*)|$)/', $name, $m)) {
|
||||||
$segments = array($m['base']);
|
$segments = array($m['base']);
|
||||||
while (preg_match('/^\[(?P<segment>.*?)\](?P<extra>.*)$/', $m['extra'], $m)) {
|
while (!empty($m['extra'])) {
|
||||||
|
if (preg_match('/^\[(?P<segment>.*?)\](?P<extra>.*)$/', $m['extra'], $m)) {
|
||||||
$segments[] = $m['segment'];
|
$segments[] = $m['segment'];
|
||||||
|
} else {
|
||||||
|
throw new \InvalidArgumentException(sprintf('Malformed field path "%s"', $name));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $segments;
|
return $segments;
|
||||||
|
@ -247,6 +247,18 @@ class FormTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSetValueOnMultiValuedFieldsWithMalformedName()
|
||||||
|
{
|
||||||
|
$form = $this->createForm('<form><input type="text" name="foo[bar]" value="bar" /><input type="text" name="foo[baz]" value="baz" /><input type="submit" /></form>');
|
||||||
|
|
||||||
|
try {
|
||||||
|
$form['foo[bar'] = 'bar';
|
||||||
|
$this->fail('->offsetSet() throws an \InvalidArgumentException exception if the name is malformed.');
|
||||||
|
} catch (\InvalidArgumentException $e) {
|
||||||
|
$this->assertTrue(true, '->offsetSet() throws an \InvalidArgumentException exception if the name is malformed.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function testOffsetUnset()
|
public function testOffsetUnset()
|
||||||
{
|
{
|
||||||
$form = $this->createForm('<form><input type="text" name="foo" value="foo" /><input type="submit" /></form>');
|
$form = $this->createForm('<form><input type="text" name="foo" value="foo" /><input type="submit" /></form>');
|
||||||
|
Reference in New Issue
Block a user