Skip to content

Commit 1d96c5c

Browse files
committed
Fix parsing empty files with mb off
Closes #100
1 parent 06ede45 commit 1d96c5c

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

lib/Sabberworm/CSS/Parser.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ public function __construct($sText, Settings $oParserSettings = null) {
4343
if ($this->oParserSettings->bMultibyteSupport) {
4444
$this->aText = preg_split('//u', $sText, null, PREG_SPLIT_NO_EMPTY);
4545
} else {
46-
$this->aText = str_split($sText);
46+
if($sText === '') {
47+
$this->aText = array();
48+
} else {
49+
$this->aText = str_split($sText);
50+
}
4751
}
4852
$this->blockRules = explode('/', AtRule::BLOCK_RULES);
4953

tests/Sabberworm/CSS/ParserTest.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,21 @@ function testComments() {
377377
$this->assertSame($sExpected, $oDoc->render());
378378
}
379379

380-
function parsedStructureForFile($sFileName) {
380+
function testEmptyFile() {
381+
$oDoc = $this->parsedStructureForFile('-empty', Settings::create()->withMultibyteSupport(true));
382+
$sExpected = '';
383+
$this->assertSame($sExpected, $oDoc->render());
384+
}
385+
386+
function testEmptyFileMbOff() {
387+
$oDoc = $this->parsedStructureForFile('-empty', Settings::create()->withMultibyteSupport(false));
388+
$sExpected = '';
389+
$this->assertSame($sExpected, $oDoc->render());
390+
}
391+
392+
function parsedStructureForFile($sFileName, $oSettings = null) {
381393
$sFile = dirname(__FILE__) . '/../../files' . DIRECTORY_SEPARATOR . "$sFileName.css";
382-
$oParser = new Parser(file_get_contents($sFile));
394+
$oParser = new Parser(file_get_contents($sFile), $oSettings);
383395
return $oParser->parse();
384396
}
385397

tests/files/-empty.css

Whitespace-only changes.

0 commit comments

Comments
 (0)