Skip to content

Commit 887757e

Browse files
Allow whitespace in types
1 parent 4dcb217 commit 887757e

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/Symfony/Component/OptionsResolver/OptionsResolver.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,7 @@ public function offsetGet(mixed $option, bool $triggerDeprecation = true): mixed
11411141

11421142
private function verifyTypes(string $type, mixed $value, ?array &$invalidTypes = null, int $level = 0): bool
11431143
{
1144+
$type = trim($type);
11441145
$allowedTypes = $this->splitOutsideParenthesis($type);
11451146
if (\count($allowedTypes) > 1) {
11461147
foreach ($allowedTypes as $allowedType) {

src/Symfony/Component/OptionsResolver/Tests/OptionsResolverTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,18 @@ public function testResolveTypedWithUnion()
790790
$this->assertSame(['foo' => '1'], $options);
791791
}
792792

793+
public function testResolveTypedWithUnionAndWhitespaces()
794+
{
795+
$this->resolver->setDefined('foo');
796+
$this->resolver->setAllowedTypes('foo', 'string | int');
797+
798+
$options = $this->resolver->resolve(['foo' => 1]);
799+
$this->assertSame(['foo' => 1], $options);
800+
801+
$options = $this->resolver->resolve(['foo' => '1']);
802+
$this->assertSame(['foo' => '1'], $options);
803+
}
804+
793805
public function testResolveTypedWithUnionOfClasse()
794806
{
795807
$this->resolver->setDefined('foo');

0 commit comments

Comments
 (0)