Skip to content

Commit b50f228

Browse files
committed
Add ParserState::EOL and support it in consumeUntil
1 parent e795c88 commit b50f228

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

lib/Sabberworm/CSS/CSSList/CSSList.php

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -111,24 +111,11 @@ private static function parseAtRule(ParserState $oParserState) {
111111
$oLocation = URL::parse($oParserState);
112112
$oParserState->consumeWhiteSpace();
113113
$sMediaQuery = null;
114-
try {
115-
if (!$oParserState->comes(';')) {
116-
$sMediaQuery = $oParserState->consumeUntil(';');
117-
}
114+
if (!$oParserState->comes(';')) {
115+
$sMediaQuery = $oParserState->consumeUntil(array(';', ParserState::EOF));
116+
}
117+
if (!$oParserState->isEnd()) {
118118
$oParserState->consume(';');
119-
} catch (UnexpectedEOFException $e) {
120-
// Save the media query if present
121-
$sMediaQuery = '';
122-
try {
123-
while (!$oParserState->isEnd()) {
124-
$sMediaQuery .= $oParserState->consume(1);
125-
}
126-
} catch (UnexpectedEOFException $e) {}
127-
128-
$sMediaQuery = trim($sMediaQuery);
129-
if ($sMediaQuery === '') {
130-
$sMediaQuery = null;
131-
}
132119
}
133120
return new Import($oLocation, $sMediaQuery, $iIdentifierLineNum);
134121
} else if ($sIdentifier === 'charset') {

lib/Sabberworm/CSS/Parsing/ParserState.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
use Sabberworm\CSS\Settings;
88

99
class ParserState {
10+
const EOF = null;
11+
1012
private $oParserSettings;
1113

1214
private $sText;
@@ -230,9 +232,13 @@ public function consumeUntil($aEnd, $bIncludeEnd = false, $consumeEnd = false, a
230232
}
231233
}
232234
} catch (UnexpectedEOFException $e) {
233-
// Reset the position and forward the EOF exception, so the caller can distinguish between EOF and the standard unexpected token error
234-
$this->iCurrentPosition = $start;
235-
throw $e;
235+
if (in_array(self::EOF, $aEnd)) {
236+
return $out;
237+
} else {
238+
// Reset the position and forward the EOF exception, so the caller can distinguish between EOF and the standard unexpected token error
239+
$this->iCurrentPosition = $start;
240+
throw $e;
241+
}
236242
}
237243

238244
$this->iCurrentPosition = $start;

0 commit comments

Comments
 (0)