Skip to content

Commit 9fe11c6

Browse files
committed
deprecate using invalid names for buttons
1 parent 7377265 commit 9fe11c6

File tree

5 files changed

+45
-1
lines changed

5 files changed

+45
-1
lines changed

UPGRADE-4.3.md

Lines 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

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: 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

Lines 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

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 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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy