Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4002e6f

Browse files
committed
[Form] Disallow passing non-array values to 'choices' option of ChoiceType and its derivatives
1 parent 1e75013 commit 4002e6f

File tree

6 files changed

+51
-0
lines changed

6 files changed

+51
-0
lines changed

src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
239239
));
240240

241241
$resolver->setAllowedTypes(array(
242+
'choices' => array('null', 'array'),
242243
'choice_list' => array('null', 'Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface'),
243244
'preferred_choices' => 'array',
244245
));

src/Symfony/Component/Form/Tests/Extension/Core/Type/CountryTypeTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,14 @@ public function testUnknownCountryIsNotIncluded()
5050
}
5151
}
5252
}
53+
54+
/**
55+
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
56+
*/
57+
public function testSetInvalidChoices()
58+
{
59+
$this->factory->create('country', null, array(
60+
'choices' => 'bad value',
61+
));
62+
}
5363
}

src/Symfony/Component/Form/Tests/Extension/Core/Type/CurrencyTypeTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,14 @@ public function testCurrenciesAreSelectable()
3434
$this->assertContains(new ChoiceView('USD', 'USD', 'US Dollar'), $choices, '', false, false);
3535
$this->assertContains(new ChoiceView('SIT', 'SIT', 'Slovenian Tolar'), $choices, '', false, false);
3636
}
37+
38+
/**
39+
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
40+
*/
41+
public function testSetInvalidChoices()
42+
{
43+
$this->factory->create('currency', null, array(
44+
'choices' => 'bad value',
45+
));
46+
}
3747
}

src/Symfony/Component/Form/Tests/Extension/Core/Type/LanguageTypeTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,14 @@ public function testMultipleLanguagesIsNotIncluded()
4545

4646
$this->assertNotContains(new ChoiceView('mul', 'mul', 'Mehrsprachig'), $choices, '', false, false);
4747
}
48+
49+
/**
50+
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
51+
*/
52+
public function testSetInvalidChoices()
53+
{
54+
$this->factory->create('language', null, array(
55+
'choices' => 'bad value',
56+
));
57+
}
4858
}

src/Symfony/Component/Form/Tests/Extension/Core/Type/LocaleTypeTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,14 @@ public function testLocalesAreSelectable()
3434
$this->assertContains(new ChoiceView('en_GB', 'en_GB', 'English (United Kingdom)'), $choices, '', false, false);
3535
$this->assertContains(new ChoiceView('zh_Hant_MO', 'zh_Hant_MO', 'Chinese (Traditional, Macau SAR China)'), $choices, '', false, false);
3636
}
37+
38+
/**
39+
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
40+
*/
41+
public function testSetInvalidChoices()
42+
{
43+
$this->factory->create('locale', null, array(
44+
'choices' => 'bad value',
45+
));
46+
}
3747
}

src/Symfony/Component/Form/Tests/Extension/Core/Type/TimezoneTypeTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,14 @@ public function testTimezonesAreSelectable()
2727
$this->assertArrayHasKey('America', $choices);
2828
$this->assertContains(new ChoiceView('America/New_York', 'America/New_York', 'New York'), $choices['America'], '', false, false);
2929
}
30+
31+
/**
32+
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
33+
*/
34+
public function testSetInvalidChoices()
35+
{
36+
$this->factory->create('timezone', null, array(
37+
'choices' => 'bad value',
38+
));
39+
}
3040
}

0 commit comments

Comments
 (0)