Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cacc50b

Browse files
committed
support Stringable instances in CharsetValidator
1 parent c28c9e7 commit cacc50b

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function validate(mixed $value, Constraint $constraint): void
3131
return;
3232
}
3333

34-
if (!\is_string($value)) {
34+
if (!\is_string($value) && !$value instanceof \Stringable) {
3535
throw new UnexpectedValueException($value, 'string');
3636
}
3737

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ protected function createValidator(): CharsetValidator
2626
/**
2727
* @dataProvider provideValidValues
2828
*/
29-
public function testEncodingIsValid(string $value, array $encodings)
29+
public function testEncodingIsValid(string|\Stringable $value, array $encodings)
3030
{
3131
$this->validator->validate($value, new Charset(encodings: $encodings));
3232

@@ -66,6 +66,12 @@ public static function provideValidValues()
6666
yield ['my ûtf 8', ['ASCII', 'UTF-8']];
6767
yield ['my ûtf 8', ['UTF-8']];
6868
yield ['ώ', ['UTF-16']];
69+
yield [new class() implements \Stringable {
70+
public function __toString(): string
71+
{
72+
return 'my ûtf 8';
73+
}
74+
}, ['UTF-8']];
6975
}
7076

7177
public static function provideInvalidValues()

0 commit comments

Comments
 (0)