8000 deprecate using invalid names for buttons · symfony/symfony@21c1170 · GitHub
[go: up one dir, main page]

Skip to content

Commit 21c1170

Browse files
committed
deprecate using invalid names for buttons
1 parent b452c01 commit 21c1170

File tree

5 files changed

+36
-1
lines changed

5 files changed

+36
-1
lines changed

UPGRADE-4.2.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ Finder
5555
Form
5656
----
5757

58+
* Using names for buttons that do not start with a letter, a digit, or an underscore is deprecated and will lead to an
59+
exception in 5.0.
60+
61+
* Using names for buttons that do not contain only letters, digits, underscores, hyphens, and colons is deprecated and
62+
will lead to an exception in 5.0.
63+
5864
* The `getExtendedType()` method of the `FormTypeExtensionInterface` is deprecated and will be removed in 5.0. Type
5965
extensions must implement the static `getExtendedTypes()` method instead and return an iterable of extended types.
6066

UPGRADE-5.0.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ Finder
7272
Form
7373
----
7474

75+
* Using names for buttons that do not start with a letter, a digit, or an underscore leads to an exception.
76+
77+
* Using names for buttons that do not contain only letters, digits, underscores, hyphens, and colons leads to an
78+
exception.
79+
7580
* The `getExtendedType()` method was removed from the `FormTypeExtensionInterface`. It is replaced by the the static
7681
`getExtendedTypes()` method which must return an iterable of extended types.
7782

src/Symfony/Component/Form/ButtonBuilder.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,17 @@ public function __construct(?string $name, array $options = array())
6363

6464
$this->name = $name;
6565
$this->options = $options;
66+
67+
if (!preg_match('/^[a-z0-9_]$/', $name[0])) {
68+
@trigger_error(sprintf('Using names for buttons that do not start with a letter, a digit, or an underscore is deprecated since Symfony 4.2 and will trigger an exception in 5.0 ("%s" given).', $name), E_USER_DEPRECATED);
69+
}
70+
71+
if (!preg_match('/^[a-zA-Z0-9_][a-zA-Z0-9_\-:]*$/D', $name)) {
72+
@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.2 and will trigger an exception in 5.0.', $name), E_USER_DEPRECATED);
73+
}
74+
75+
// to be added in 5.0
76+
// FormConfigBuilder::validateName($name);
6677
}
6778

6879
/**

src/Symfony/Component/Form/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ CHANGELOG
44
4.2.0
55
-----
66

7+
* Using names for buttons that do not start with a letter, a digit, or an underscore is deprecated and will lead to an
8+
exception in 5.0.
9+
10+
* Using names for buttons that do not contain only letters, digits, underscores, hyphens, and colons is deprecated and
11+
will lead to an exception in 5.0.
12+
713
* The `getExtendedType()` method of the `FormTypeExtensionInterface` is deprecated and will be removed in 5.0. Type
814
extensions must implement the static `getExtendedTypes()` method instead and return an iterable of extended types.
915

src/Symfony/Component/Form/Tests/ButtonBuilderTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ public function getValidNames()
2828
array('foo'),
2929
array('0'),
3030
array(0),
31-
array('button[]'),
3231
);
3332
}
3433

@@ -40,6 +39,14 @@ public function testValidNames($name)
4039
$this->assertInstanceOf('\Symfony\Component\Form\ButtonBuilder', new ButtonBuilder($name));
4140
}
4241

42+
/**
43+
* @group legacy
44+
*/
45+
public function testNameContainingSquareBrackets()
46+
{
47+
$this->assertInstanceOf('\Symfony\Component\Form\ButtonBuilder', new ButtonBuilder('button[]'));
48+
}
49+
4350
public function getInvalidNames()
4451
{
4552
return array(

0 commit comments

Comments
 (0)
0