Skip to content

Commit d718287

Browse files
committed
Strictly enforce valid value is provided to setValue()
1 parent b724647 commit d718287

1 file changed

Lines changed: 4 additions & 8 deletions

File tree

src/Property/Selector/Combinator.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,15 @@ public function getValue(): string
7272
/**
7373
* @param non-empty-string $value
7474
*
75-
* @throws \UnexpectedValueException
75+
* @throws \UnexpectedValueException if `$value` is not either space, '>', '+' or '~'
7676
*/
7777
public function setValue(string $value): void
7878
{
79-
// Allow extra and other whitespace even if not publicly documented.
80-
$trimmedValue = \trim($value);
81-
82-
// But reject anything else that is not a combinator.
83-
if (!\in_array($trimmedValue, ['', '>', '+', '~'], true)) {
84-
throw new \UnexpectedValueException('`' . $trimmedValue . '` is not a valid selector combinator.');
79+
if (!\in_array($value, [' ', '>', '+', '~'], true)) {
80+
throw new \UnexpectedValueException('`' . $value . '` is not a valid selector combinator.');
8581
}
8682

87-
$this->value = $trimmedValue !== '' ? $trimmedValue : ' ';
83+
$this->value = $value;
8884
}
8985

9086
/**

0 commit comments

Comments
 (0)