8000 Fix · symfony/symfony@c5fd1c9 · GitHub
[go: up one dir, main page]

Skip to content

Commit c5fd1c9

Browse files
Fix
1 parent a454b19 commit c5fd1c9

File tree

2 files changed

+35
-9
lines changed
< 8000 ul role="tree" aria-label="File Tree" data-truncate-text="true" class="prc-TreeView-TreeViewRootUlStyles-eZtxW">
  • src/Symfony/Component/OptionsResolver
  • 2 files changed

    +35
    -9
    lines changed

    src/Symfony/Component/OptionsResolver/OptionsResolver.php

    Lines changed: 22 additions & 9 deletions
    Original file line numberDiff line numberDiff line change
    @@ -1141,15 +1141,8 @@ 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-
    if (str_starts_with($type, '(') && str_ends_with($type, ')')) {
    1145-
    $substr = substr($type, 1, -1);
    1146-
    1147-
    // Ensure we didn't simplify `(A)|(B)` into `A)|(B`
    1148-
    $openingPos = strpos($substr, '(');
    1149-
    $closingPos = strpos($substr, ')');
    1150-
    if (false === $closingPos || $closingPos > $openingPos) {
    1151-
    return $this->verifyTypes($substr, $value, $invalidTypes, $level);
    1152-
    }
    1144+
    if ($this->isEnclosedWithParenthesis($type)) {
    1145+
    return $this->verifyTypes(substr($type, 1, -1), $value, $invalidTypes, $level);
    11531146
    }
    11541147

    11551148
    if (\is_array($value) && str_ends_with($type, '[]')) {
    @@ -1183,6 +1176,26 @@ private function verifyTypes(string $type, mixed $value, ?array &$invalidTypes =
    11831176
    return false;
    11841177
    }
    11851178

    1179+
    private function isEnclosedWithParenthesis(string $string): bool
    1180+
    {
    1181+
    if (!str_starts_with($string, '(') || !str_ends_with($string, ')')) {
    1182+
    return false;
    1183+
    }
    1184+
    1185+
    $openedParenthesis = 1;
    1186+
    $i = 1;
    1187+
    while (isset($string[$i]) && $openedParenthesis > 0) {
    1188+
    if ($string[$i] === '(') {
    1189+
    $openedParenthesis++;
    1190+
    } elseif ($string[$i] === ')') {
    1191+
    $openedParenthesis--;
    1192+
    }
    1193+
    $i++;
    1194+
    }
    1195+
    1196+
    return $i === strlen($string);
    1197+
    }
    1198+
    11861199
    /**
    11871200
    * Returns whether a resolved option with the given name exists.
    11881201
    *

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

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

    793+
    794+
    public function testResolveTypedWithUnionOfArray()
    795+
    {
    796+
    $this->resolver->setDefined('foo');
    797+
    $this->resolver->setAllowedTypes('foo', '((string|int)[])|((bool|int)[])');
    798+
    799+
    $options = $this->resolver->resolve(['foo' => [1, '1']]);
    800+
    $this->assertSame(['foo' => [1, '1']], $options);
    801+
    802+
    $options = $this->resolver->resolve(['foo' => [1, true]]);
    803+
    $this->assertSame(['foo' => [1, true]], $options);
    804+
    }
    805+
    793806
    public function testResolveTypedWithUnionUselessParentheses()
    794807
    {
    795808
    $this->resolver->setDefined('foo');

    0 commit comments

    Comments
     (0)
    0