8000 [DomCrawler] No more exception on field name with strange format by fabpot · Pull Request #19138 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DomCrawler] No more exception on field name with strange format #19138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 22, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
finished previous commit
  • Loading branch information
fabpot committed Jun 22, 2016
commit e204913a6762944dd4bc8d29fee953f4ba84b2b5
2 changes: 0 additions & 2 deletions src/Symfony/Component/DomCrawler/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,6 @@ public function has($name)
* Removes a field from the form.
*
* @param string $name The field name
*
* @throws \InvalidArgumentException when the name is malformed
*/
public function remove($name)
{
Expand Down
10 changes: 1 addition & 9 deletions src/Symfony/Component/DomCrawler/FormFieldRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ class FormFieldRegistry
* Adds a field to the registry.
*
* @param FormField $field The field
*
* @throws \InvalidArgumentException when the name is malformed
*/
public function add(FormField $field)
{
Expand All @@ -52,8 +50,6 @@ public function add(FormField $field)
* Removes a field and its children from the registry.
*
* @param string $name The fully qualified name of the base field
*
* @throws \InvalidArgumentException when the name is malformed
*/
public function remove($name)
{
Expand All @@ -76,7 +72,6 @@ public function remove($name)
*
* @return mixed The value of the field
*
* @throws \InvalidArgumentException when the name is malformed
* @throws \InvalidArgumentException if the field does not exist
*/
public function &get($name)
Expand Down Expand Up @@ -118,7 +113,6 @@ public function has($name)
* @param string $name The fully qualified name of the field
* @param mixed $value The value
*
* @throws \InvalidArgumentException when the name is malformed
* @throws \InvalidArgumentException if the field does not exist
*/
public function set($name, $value)
Expand Down Expand Up @@ -199,8 +193,6 @@ private function walk(array $array, $base = '', array &$output = array())
* @param string $name The name of the field
*
* @return string[] The list of segments
*
* @throws \InvalidArgumentException when the name is malformed
*/
private function getSegments($name)
{
Expand All @@ -218,6 +210,6 @@ private function getSegments($name)
return $segments;
}

return [$name];
return array($name);
}
}
51 changes: 9 additions & 42 deletions src/Symfony/Component/DomCrawler/Tests/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,18 +345,6 @@ public function testGetSetValue()
}
}

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 testDisableValidation()
{
$form = $this->createForm('<form>
Expand Down Expand Up @@ -681,31 +669,19 @@ public function testTypeAttributeIsCaseInsensitive()
$this->assertTrue($form->has('example.y'), '->has() returns true if the image input was correctly turned into an x and a y fields');
}

/**
* @expectedException \InvalidArgumentException
*/
public function testFormFieldRegistryAddThrowAnExceptionWhenTheNameIsMalformed()
public function testFormFieldRegistryAcceptAnyNames()
{
$registry = new FormFieldRegistry();
$registry->add($this->getFormFieldMock('[foo]'));
}
$field = $this->getFormFieldMock('[t:dbt%3adate;]data_daterange_enddate_value');

/**
* @expectedException \InvalidArgumentException
*/
public function testFormFieldRegistryRemoveThrowAnExceptionWhenTheNameIsMalformed()
{
$registry = new FormFieldRegistry();
$registry->remove('[foo]');
}
$registry->add($field);
$this->assertEquals($field, $registry->get('[t:dbt%3adate;]data_daterange_enddate_value'));
$registry->set('[t:dbt%3adate;]data_daterange_enddate_value', null);

/**
* @expectedException \InvalidArgumentException
*/
public function testFormFieldRegistryGetThrowAnExceptionWhenTheNameIsMalformed()
{
$registry = new FormFieldRegistry();
$registry->get('[foo]');
$form = $this->createForm('<form><input type="text" name="[t:dbt%3adate;]data_daterange_enddate_value" value="bar" /><input type="submit" /></form>');
$form['[t:dbt%3adate;]data_daterange_enddate_value'] = 'bar';

$registry->remove('[t:dbt%3adate;]data_daterange_enddate_value');
}

/**
Expand All @@ -717,15 +693,6 @@ public function testFormFieldRegistryGetThrowAnExceptionWhenTheFieldDoesNotExist
$registry->get('foo');
}

/**
* @expectedException \InvalidArgumentException
*/
public function testFormFieldRegistrySetThrowAnExceptionWhenTheNameIsMalformed()
{
$registry = new FormFieldRegistry();
$registry->set('[foo]', null);
}

/**
* @expectedException \InvalidArgumentException
*/
Expand Down
0