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 b0af2bb

Browse filesBrowse files
committed
deprecate using invalid names for buttons
1 parent 5c2cee5 commit b0af2bb
Copy full SHA for b0af2bb

File tree

5 files changed

+38
-1
lines changed
Filter options

5 files changed

+38
-1
lines changed

‎UPGRADE-4.3.md

Copy file name to clipboardExpand all lines: UPGRADE-4.3.md
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,12 @@ Config
55
------
66

77
* Deprecated using environment variables with `cannotBeEmpty()` if the value is validated with `validate()`
8+
9+
Form
10+
----
11+
12+
* Using names for buttons that do not start with a letter, a digit, or an underscore is deprecated and will lead to an
13+
exception in 5.0.
14+
15+
* Using names for buttons that do not contain only letters, digits, underscores, hyphens, and colons is deprecated and
16+
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
@@ -73,6 +73,11 @@ Finder
7373
Form
7474
----
7575

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

‎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 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
* added `block_prefix` option to `BaseType`.
812

913
4.2.0

‎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.