Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9fe11c6

Browse filesBrowse files
committed
deprecate using invalid names for buttons
1 parent 7377265 commit 9fe11c6
Copy full SHA for 9fe11c6

File tree

5 files changed

+45
-1
lines changed
Filter options

5 files changed

+45
-1
lines changed

‎UPGRADE-4.3.md

Copy file name to clipboard
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
UPGRADE FROM 4.2 to 4.3
2+
=======================
3+
4+
Form
5+
----
6+
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.

‎UPGRADE-5.0.md

Copy file name to clipboardExpand all lines: UPGRADE-5.0.md
+5Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/ButtonBuilder.php
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,18 @@ 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_].*)?(.*[^a-zA-Z0-9_\-:].*)?$/D', $name, $matches)) {
68+
if (isset($matches[1])) {
69+
@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 trigger an exception in 5.0 ("%s" given).', $name), E_USER_DEPRECATED);
70+
}
71+
if (isset($matches[2])) {
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.3 and will trigger an exception in 5.0.', $name), E_USER_DEPRECATED);
73+
}
74+
}
75+
76+
// to be added in 5.0
77+
// FormConfigBuilder::validateName($name);
6678
}
6779

6880
/**

‎src/Symfony/Component/Form/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/CHANGELOG.md
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
CHANGELOG
22
=========
33

4+
4.3.0
5+
-----
6+
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+
413
4.2.0
514
-----
615

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/ButtonBuilderTest.php
+8-1Lines 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 testNameContainingIllegalCharacters()
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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.