Skip to content

Commit 2943d9f

Browse files
committed
Move selector validation outside of the Selector's constructor
1 parent 397ca39 commit 2943d9f

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

lib/Sabberworm/CSS/CSSList/CSSList.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,9 @@ public function removeDeclarationBlockBySelector($mSelector, $bRemoveAll = false
272272
}
273273
foreach ($mSelector as $iKey => &$mSel) {
274274
if (!($mSel instanceof Selector)) {
275+
if (!Selector::isValid($mSel)) {
276+
throw new UnexpectedTokenException("Selector did not match '" . Selector::SELECTOR_VALIDATION_RX . "'.", $mSel, "custom");
277+
}
275278
$mSel = new Selector($mSel);
276279
}
277280
}

lib/Sabberworm/CSS/Property/Selector.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ public static function isValid($sSelector) {
4949
}
5050

5151
public function __construct($sSelector, $bCalculateSpecificity = false) {
52-
if (!Selector::isValid($sSelector)) {
53-
throw new UnexpectedTokenException("Selector did not match '" . self::SELECTOR_VALIDATION_RX . "'.", $sSelector, "custom");
54-
}
5552
$this->setSelector($sSelector);
5653
if ($bCalculateSpecificity) {
5754
$this->getSpecificity();

lib/Sabberworm/CSS/RuleSet/DeclarationBlock.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ public function setSelectors($mSelector) {
7070
}
7171
foreach ($this->aSelectors as $iKey => $mSelector) {
7272
if (!($mSelector instanceof Selector)) {
73+
if (!Selector::isValid($mSelector)) {
74+
throw new UnexpectedTokenException("Selector did not match '" . Selector::SELECTOR_VALIDATION_RX . "'.", $mSelector, "custom");
75+
}
7376
$this->aSelectors[$iKey] = new Selector($mSelector);
7477
}
7578
}

0 commit comments

Comments
 (0)