8000 bug #19138 [DomCrawler] No more exception on field name with strange … · symfony/symfony@eaca0bb · GitHub
[go: up one dir, main page]

Skip to content

Commit eaca0bb

Browse files
committed
bug #19138 [DomCrawler] No more exception on field name with strange format (guiled, fabpot)
This PR was merged into the 2.7 branch. Discussion ---------- [DomCrawler] No more exception on field name with strange format | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #18569, #18570 | License | MIT | Doc PR | n/a Commits ------- e204913 finished previous commit 953a383 No more exception for malformed input name
2 parents f28eb9a + e204913 commit eaca0bb

File tree

3 files changed

+13
-55
lines changed

3 files changed

+13
-55
lines changed

src/Symfony/Component/DomCrawler/Form.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,6 @@ public function has($name)
246246
* Removes a field from the form.
247247
*
248248
* @param string $name The field name
249-
*
250-
* @throws \InvalidArgumentException when the name is malformed
251249
*/
252250
public function remove($name)
253251
{

src/Symfony/Component/DomCrawler/FormFieldRegistry.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ class FormFieldRegistry
2626
* Adds a field to the registry.
2727
*
2828
* @param FormField $field The field
29-
*
30-
* @throws \InvalidArgumentException when the name is malformed
3129
*/
3230
public function add(FormField $field)
3331
{
@@ -52,8 +50,6 @@ public function add(FormField $field)
5250
* Removes a field and its children from the registry.
5351
*
5452
* @param string $name The fully qualified name of the base field
55-
*
56-
* @throws \InvalidArgumentException when the name is malformed
5753
*/
5854
public function remove($name)
5955
{
@@ -76,7 +72,6 @@ public function remove($name)
7672
*
7773
* @return mixed The value of the field
7874
*
79-
* @throws \InvalidArgumentException when the name is malformed
8075
* @throws \InvalidArgumentException if the field does not exist
8176
*/
8277
public function &get($name)
@@ -118,7 +113,6 @@ public function has($name)
118113
* @param string $name The fully qualified name of the field
119114
* @param mixed $value The value
120115
*
121-
* @throws \InvalidArgumentException when the name is malformed
122116
* @throws \InvalidArgumentException if the field does not exist
123117
*/
124118
public function set($name, $value)
@@ -199,24 +193,23 @@ private function walk(array $array, $base = '', array &$output = array())
199193
* @param string $name The name of the field
200194
*
201195
* @return string[] The list of segments
202-
*
203-
* @throws \InvalidArgumentException when the name is malformed
204196
*/
205197
private function getSegments($name)
206198
{
207199
if (preg_match('/^(?P<base>[^[]+)(?P<extra>(\[.*)|$)/', $name, $m)) {
208200
$segments = array($m['base']);
209201
while (!empty($m['extra'])) {
210-
if (preg_match('/^\[(?P<segment>.*?)\](?P<extra>.*)$/', $m['extra'], $m)) {
202+
$extra = $m['extra'];
203+
if (preg_match('/^\[(?P<segment>.*?)\](?P<extra>.*)$/', $extra, $m)) {
211204
$segments[] = $m['segment'];
212205
} else {
213-
throw new \InvalidArgumentException(sprintf('Malformed field path "%s"', $name));
206+
$segments[] = $extra;
214207
}
215208
}
216209

217210
return $segments;
218211
}
219212

220-
throw new \InvalidArgumentException(sprintf('Malformed field path "%s"', $name));
213+
return array($name);
221214
}
222215
}

src/Symfony/Component/DomCrawler/Tests/FormTest.php

Lines changed: 9 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -345,18 +345,6 @@ public function testGetSetValue()
345345
}
346346
}
347347

348-
public function testSetValueOnMultiValuedFieldsWithMalformedName()
349-
{
350-
$form = $this->createForm('<form><input type="text" name="foo[bar]" value="bar" /><input type="text" name="foo[baz]" value="baz" /><input type="submit" /></form>');
351-
352-
try {
353-
$form['foo[bar'] = 'bar';
354-
$this->fail('->offsetSet() throws an \InvalidArgumentException exception if the name is malformed.');
355-
} catch (\InvalidArgumentException $e) {
356-
$this->assertTrue(true, '->offsetSet() throws an \InvalidArgumentException exception if the name is malformed.');
357-
}
358-
}
359-
360348
public function testDisableValidation()
361349
{
362350
$form = $this->createForm('<form>
@@ -681,31 +669,19 @@ public function testTypeAttributeIsCaseInsensitive()
681669
$this->assertTrue($form->has('example.y'), '->has() returns true if the image input was correctly turned into an x and a y fields');
682670
}
683671

684-
/**
685-
* @expectedException \InvalidArgumentException
686-
*/
687-
public function testFormFieldRegistryAddThrowAnExceptionWhenTheNameIsMalformed()
672+
public function testFormFieldRegistryAcceptAnyNames()
688673
{
689-
$registry = new FormFieldRegistry();
690-
$registry->add($this->getFormFieldMock('[foo]'));
691-
}
674+
$field = $this->getFormFieldMock('[t:dbt%3adate;]data_daterange_enddate_value');
692675

693-
/**
694-
* @expectedException \InvalidArgumentException
695-
*/
696-
public function testFormFieldRegistryRemoveThrowAnExceptionWhenTheNameIsMalformed()
697-
{
698676
$registry = new FormFieldRegistry();
699-
$registry->remove('[foo]');
700-
}
677+
$registry->add($field);
678+
$this->assertEquals($field, $registry->get('[t:dbt%3adate;]data_daterange_enddate_value'));
679+
$registry->set('[t:dbt%3adate;]data_daterange_enddate_value', null);
701680

702-
/**
703-
* @expectedException \InvalidArgumentException
704-
*/
705-
public function testFormFieldRegistryGetThrowAnExceptionWhenTheNameIsMalformed()
706-
{
707-
$registry = new FormFieldRegistry();
708-
$registry->get('[foo]');
681+
$form = $this->createForm('<form><input type="text" name="[t:dbt%3adate;]data_daterange_enddate_value" value="bar" /><input type="submit" /></form>');
682+
$form['[t:dbt%3adate;]data_daterange_enddate_value'] = 'bar';
683+
684+
$registry->remove('[t:dbt%3adate;]data_daterange_enddate_value');
709685
}
710686

711687
/**
@@ -717,15 +693,6 @@ public function testFormFieldRegistryGetThrowAnExceptionWhenTheFieldDoesNotExist
717693
$registry->get('foo');
718694
}
719695

720-
/**
721-
* @expectedException \InvalidArgumentException
722-
*/
723-
public function testFormFieldRegistrySetThrowAnExceptionWhenTheNameIsMalformed()
724-
{
725-
$registry = new FormFieldRegistry();
726-
$registry->set('[foo]', null);
727-
}
728-
729696
/**
730697
* @expectedException \InvalidArgumentException
731698
*/

0 commit comments

Comments
 (0)
0