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 405aa54

Browse filesBrowse files
committed
deprecate using invalid names for buttons
1 parent 2cad97b commit 405aa54
Copy full SHA for 405aa54

File tree

5 files changed

+32
-2
lines changed
Filter options

5 files changed

+32
-2
lines changed

‎UPGRADE-4.3.md

Copy file name to clipboardExpand all lines: UPGRADE-4.3.md
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ Config
2323
Form
2424
----
2525

26+
* Using names for buttons that do not start with a letter, a digit, or an underscore is deprecated and will lead to an
27+
exception in 5.0.
28+
* Using names for buttons that do not contain only letters, digits, underscores, hyphens, and colons is deprecated and
29+
will lead to an exception in 5.0.
2630
* Using the `date_format`, `date_widget`, and `time_widget` options of the `DateTimeType` when the `widget` option is
2731
set to `single_text` is deprecated.
2832

‎UPGRADE-5.0.md

Copy file name to clipboardExpand all lines: UPGRADE-5.0.md
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ Finder
7777

7878
Form
7979
----
80-
80+
81+
* Using names for buttons that do not start with a letter, a digit, or an underscore leads to an exception.
82+
* Using names for buttons that do not contain only letters, digits, underscores, hyphens, and colons leads to an
83+
exception.
8184
* Using the `date_format`, `date_widget`, and `time_widget` options of the `DateTimeType` when the `widget` option is
8285
set to `single_text` is not supported anymore.
8386
* The `getExtendedType()` method was removed from the `FormTypeExtensionInterface`. It is replaced by the the static

‎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 = [])
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 throw 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 throw 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
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ CHANGELOG
44
4.3.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+
* Using names for buttons that do not contain only letters, digits, underscores, hyphens, and colons is deprecated and
10+
will lead to an exception in 5.0.
711
* deprecated using the `date_format`, `date_widget`, and `time_widget` options of the `DateTimeType` when the `widget`
812
option is set to `single_text`
913
* added `block_prefix` option to `BaseType`.

‎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
['foo'],
2929
['0'],
3030
[0],
31-
['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 [

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.