bug #32335 [Form] Names for buttons should start with lowercase (mcfedr)

This PR was merged into the 4.3 branch.

Discussion
----------

[Form] Names for buttons should start with lowercase

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | N/A
| License       | MIT
| Doc PR        | N/A

This fix changes the messages related to the changes in https://github.com/symfony/symfony/pull/28969 - the message used to state that names should start with a letter, a digit ... - so I got a confusing message:

```
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 ("Search" given).'
```

Which made me find the message, look at the regex that was used, and work out that actually it should start with a lowercase letter, and hence this PR - where I assume there is a reason that the name must start with lowercase letters.

Commits
-------

f65524e4e0 Names for buttons should start with lowercase
This commit is contained in:
Fabien Potencier 2019-09-25 21:19:30 +02:00
commit d04fdee000
5 changed files with 12 additions and 4 deletions

View File

@ -96,7 +96,7 @@ Form
----
* Using the `format` option of `DateType` and `DateTimeType` when the `html5` option is enabled is deprecated.
* Using names for buttons that do not start with a letter, a digit, or an underscore is deprecated and will lead to an
* Using names for buttons that do not start with a lowercase letter, a digit, or an underscore is deprecated and will lead to an
exception in 5.0.
* Using names for buttons that do not contain only letters, digits, underscores, hyphens, and colons is deprecated and
will lead to an exception in 5.0.

View File

@ -110,7 +110,7 @@ Form
----
* Removed support for using the `format` option of `DateType` and `DateTimeType` when the `html5` option is enabled.
* Using names for buttons that do not start with a letter, a digit, or an underscore leads to an exception.
* Using names for buttons that do not start with a lowercase letter, a digit, or an underscore leads to an exception.
* Using names for buttons that do not contain only letters, digits, underscores, hyphens, and colons leads to an
exception.
* Using the `date_format`, `date_widget`, and `time_widget` options of the `DateTimeType` when the `widget` option is

View File

@ -63,7 +63,7 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
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);
@trigger_error(sprintf('Using names for buttons that do not start with a lowercase 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);

View File

@ -6,7 +6,7 @@ CHANGELOG
* added a `symbol` option to the `PercentType` that allows to disable or customize the output of the percent character
* Using the `format` option of `DateType` and `DateTimeType` when the `html5` option is enabled is deprecated.
* Using names for buttons that do not start with a letter, a digit, or an underscore is deprecated and will lead to an
* Using names for buttons that do not start with a lowercase letter, a digit, or an underscore is deprecated and will lead to an
exception in 5.0.
* Using names for buttons that do not contain only letters, digits, underscores, hyphens, and colons is deprecated and
will lead to an exception in 5.0.

View File

@ -47,6 +47,14 @@ class ButtonBuilderTest extends TestCase
$this->assertInstanceOf('\Symfony\Component\Form\ButtonBuilder', new ButtonBuilder('button[]'));
}
/**
* @group legacy
*/
public function testNameStartingWithIllegalCharacters()
{
$this->assertInstanceOf('\Symfony\Component\Form\ButtonBuilder', new ButtonBuilder('Button'));
}
public function getInvalidNames()
{
return [