Skip to content

Commit 7c4046f

Browse files
committed
deprecate disallowing empty strings with minimum lengths
1 parent a73523b commit 7c4046f

File tree

5 files changed

+36
-0
lines changed

5 files changed

+36
-0
lines changed

UPGRADE-5.2.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
UPGRADE FROM 5.1 to 5.2
2+
=======================
3+
4+
Validator
5+
---------
6+
7+
* Being able to explicitly set the `allowEmptyString` option of the `Length` constraint to `false` without configuring
8+
a minimum length is deprecated.

UPGRADE-6.0.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ Security
113113
* Removed `LogoutSuccessHandlerInterface` and `LogoutHandlerInterface`, register a listener on the `LogoutEvent` event instead.
114114
* Removed `DefaultLogoutSuccessHandler` in favor of `DefaultLogoutListener`.
115115

116+
Validator
117+
---------
118+
119+
* Explicitly setting the `allowEmptyString` option of the `Length` constraint to `false` without configuring a minimum
120+
length leads to an exception.
121+
116122
Yaml
117123
----
118124

src/Symfony/Component/Validator/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
5.2.0
5+
-----
6+
7+
* deprecated support for explicitly setting the `allowEmptyString` option of the `Length` constraint to `false` without configuring a minimum length
8+
49
5.1.0
510
-----
611

src/Symfony/Component/Validator/Constraints/Length.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,9 @@ public function __construct($options = null)
6464
if (null !== $this->normalizer && !\is_callable($this->normalizer)) {
6565
throw new InvalidArgumentException(sprintf('The "normalizer" option must be a valid callable ("%s" given).', get_debug_type($this->normalizer)));
6666
}
67+
68+
if (false === ($options['allowEmptyString'] ?? null) && null === $this->min) {
69+
trigger_deprecation('symfony/validator', '5.2', 'Being able to set the "allowEmptyString" option to "false" without configuring a min length is deprecated.');
70+
}
6771
}
6872
}

src/Symfony/Component/Validator/Tests/Constraints/LengthTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@
1212
namespace Symfony\Component\Validator\Tests\Constraints;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
1516
use Symfony\Component\Validator\Constraints\Length;
1617

1718
/**
1819
* @author Renan Taranto <renantaranto@gmail.com>
1920
*/
2021
class LengthTest extends TestCase
2122
{
23+
use ExpectDeprecationTrait;
24+
2225
public function testNormalizerCanBeSet()
2326
{
2427
$length = new Length(['min' => 0, 'max' => 10, 'normalizer' => 'trim']);
@@ -39,4 +42,14 @@ public function testInvalidNormalizerObjectThrowsException()
3942
$this->expectExceptionMessage('The "normalizer" option must be a valid callable ("stdClass" given).');
4043
new Length(['min' => 0, 'max' => 10, 'normalizer' => new \stdClass()]);
4144
}
45+
46+
/**
47+
* @group legacy
48+
*/
49+
public function testDoNotAllowEmptyStringWithoutMinLength()
50+
{
51+
$this->expectDeprecation('Since symfony/validator 5.2: Being able to set the "allowEmptyString" option to "false" without configuring a min length is deprecated.');
52+
53+
new Length(['allowEmptyString' => false, 'max' => 5]);
54+
}
4255
}

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