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

Skip to content

[Form] Throw exception for invalid form buttons name #31705

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 1 commit into from
May 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 1 addition & 11 deletions src/Symfony/Component/Form/ButtonBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,7 @@ public function __construct(?string $name, array $options = [])
$this->name = $name;
$this->options = $options;

if (\preg_match('/^([^a-z0-9_].*)?(.*[^a-zA-Z0-9_\-:].*)?$/D', $name, $matches)) {
if (isset($matches[1])) {
@trigger_error(sprintf('Using names for buttons that do not start with a letter, a digit, or an underscore is deprecated since Symfony 4.3 and will throw an exception in 5.0 ("%s" given).', $name), E_USER_DEPRECATED);
}
if (isset($matches[2])) {
@trigger_error(sprintf('Using names for buttons that do not contain only letters, digits, underscores ("_"), hyphens ("-") and colons (":") ("%s" given) is deprecated since Symfony 4.3 and will throw an exception in 5.0.', $name), E_USER_DEPRECATED);
}
}

// to be added in 5.0
// FormConfigBuilder::validateName($name);
FormConfigBuilder::validateName($name);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/Form/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ CHANGELOG
5.0.0
-----

* Using names for buttons that do not start with a letter, a digit, or an underscore throw an exception
* Using names for buttons that do not contain only letters, digits, underscores, hyphens, and colons throw an exception.
* removed the `ChoiceLoaderInterface` implementation in `CountryType`, `LanguageType`, `LocaleType` and `CurrencyType`

4.3.0
Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Component/Form/Tests/ButtonBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public function testValidNames($name)
}

/**
* @group legacy
* @expectedException \Symfony\Component\Form\Exception\InvalidArgumentException
* @expectedExceptionMessage The name "button[]" contains illegal characters. Names should start with a letter, digit or underscore and only contain letters, digits, numbers, underscores ("_"), hyphens ("-") and colons (":").
*/
public function testNameContainingIllegalCharacters()
{
Expand Down