Skip to content

Commit 4cdc664

Browse files
authored
Merge pull request #49 from guilhermednt/improved-string-length
Improved string length checking
2 parents 85f5f42 + 42eef82 commit 4cdc664

File tree

6 files changed

+12
-8
lines changed

6 files changed

+12
-8
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## [7.0.0] - 2021-08-27
8+
### Fixed
9+
- Using `grapheme_strlen` to properly count string lengths.
10+
711
## [6.1.0] - 2021-08-27
812
### Added
913
- Readded enums as consts only

src/Entity/Constraint/MaxLengthConstraint.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function exists(): bool
3030
public function getIfCondition(Variable $variable, CodeBuilder $builder): Expr
3131
{
3232
return $builder->compare(
33-
$builder->funcCall('strlen', [$variable]),
33+
$builder->funcCall('grapheme_strlen', [$variable]),
3434
'>',
3535
$builder->val($this->maxLength)
3636
);

src/Entity/Constraint/MinLengthConstraint.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function exists(): bool
3030
public function getIfCondition(Variable $variable, CodeBuilder $builder): Expr
3131
{
3232
return $builder->compare(
33-
$builder->funcCall('strlen', [$variable]),
33+
$builder->funcCall('grapheme_strlen', [$variable]),
3434
'<',
3535
$builder->val($this->minLength)
3636
);

test/suite/functional/Generator/Schema/ItemPhp70.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,10 @@ public function setOptionalArrayWithMinMaxItems(array $optionalArrayWithMinMaxIt
241241
*/
242242
public function setOptionalStringWithMinMaxLength(string $optionalStringWithMinMaxLength): self
243243
{
244-
if (\strlen($optionalStringWithMinMaxLength) < 1) {
244+
if (\grapheme_strlen($optionalStringWithMinMaxLength) < 1) {
245245
throw new RequestValidationException(\sprintf('Invalid %s value. Given: `%s`. Length should be greater than 1.', 'optionalStringWithMinMaxLength', $optionalStringWithMinMaxLength));
246246
}
247-
if (\strlen($optionalStringWithMinMaxLength) > 5) {
247+
if (\grapheme_strlen($optionalStringWithMinMaxLength) > 5) {
248248
throw new RequestValidationException(\sprintf('Invalid %s value. Given: `%s`. Length should be less than 5.', 'optionalStringWithMinMaxLength', $optionalStringWithMinMaxLength));
249249
}
250250
$this->optionalStringWithMinMaxLength = $optionalStringWithMinMaxLength;

test/suite/functional/Generator/Schema/ItemPhp72.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,10 @@ public function setOptionalArrayWithMinMaxItems(array $optionalArrayWithMinMaxIt
234234
*/
235235
public function setOptionalStringWithMinMaxLength(string $optionalStringWithMinMaxLength): self
236236
{
237-
if (\strlen($optionalStringWithMinMaxLength) < 1) {
237+
if (\grapheme_strlen($optionalStringWithMinMaxLength) < 1) {
238238
throw new RequestValidationException(\sprintf('Invalid %s value. Given: `%s`. Length should be greater than 1.', 'optionalStringWithMinMaxLength', $optionalStringWithMinMaxLength));
239239
}
240-
if (\strlen($optionalStringWithMinMaxLength) > 5) {
240+
if (\grapheme_strlen($optionalStringWithMinMaxLength) > 5) {
241241
throw new RequestValidationException(\sprintf('Invalid %s value. Given: `%s`. Length should be less than 5.', 'optionalStringWithMinMaxLength', $optionalStringWithMinMaxLength));
242242
}
243243
$this->optionalStringWithMinMaxLength = $optionalStringWithMinMaxLength;

test/suite/functional/Generator/Schema/ItemPhp74.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,10 @@ public function setOptionalArrayWithMinMaxItems(array $optionalArrayWithMinMaxIt
206206
*/
207207
public function setOptionalStringWithMinMaxLength(string $optionalStringWithMinMaxLength): self
208208
{
209-
if (\strlen($optionalStringWithMinMaxLength) < 1) {
209+
if (\grapheme_strlen($optionalStringWithMinMaxLength) < 1) {
210210
throw new RequestValidationException(\sprintf('Invalid %s value. Given: `%s`. Length should be greater than 1.', 'optionalStringWithMinMaxLength', $optionalStringWithMinMaxLength));
211211
}
212-
if (\strlen($optionalStringWithMinMaxLength) > 5) {
212+
if (\grapheme_strlen($optionalStringWithMinMaxLength) > 5) {
213213
throw new RequestValidationException(\sprintf('Invalid %s value. Given: `%s`. Length should be less than 5.', 'optionalStringWithMinMaxLength', $optionalStringWithMinMaxLength));
214214
}
215215
$this->optionalStringWithMinMaxLength = $optionalStringWithMinMaxLength;

0 commit comments

Comments
 (0)