Skip to content

Commit

Permalink
Merge remote-tracking branch 'pa/comments-parse-fix'
Browse files Browse the repository at this point in the history
* pa/comments-parse-fix:
  Fixed comments parsing and test added
  • Loading branch information
Raphael Schweikert committed Oct 30, 2013
2 parents 7f03a04 + 21ac4d9 commit 8b773b1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/Sabberworm/CSS/Parser.php
Expand Up @@ -546,10 +546,10 @@ private function consumeWhiteSpace() {

private function consumeComment() {
if ($this->comes('/*')) {
$this->consume(2);
while ($this->consumeUntil('*', false, true)) {
if ($this->comes('/')) {
$this->consume(1);
$this->consume(1);
while ($this->consume(1) !== '') {
if ($this->comes('*/')) {
$this->consume(2);
return true;
}
}
Expand All @@ -567,6 +567,7 @@ private function consumeUntil($aEnd, $bIncludeEnd = false, $consumeEnd = false)
$start = $this->iCurrentPosition;

while (($char = $this->consume(1)) !== '') {
$this->consumeComment();
if (in_array($char, $aEnd)) {
if ($bIncludeEnd) {
$out .= $char;
Expand Down
8 changes: 8 additions & 0 deletions tests/Sabberworm/CSS/ParserTest.php
Expand Up @@ -343,6 +343,14 @@ function testListValueRemoval() {
}#unrelated {other: yes;}' . "\n", $oDoc->__toString());
}

function testComments() {
$oDoc = $this->parsedStructureForFile('comments');
$sExpected = '@import url("some/url.css") screen;.foo, #bar {background-color: #000;}
@media screen {#foo.bar {position: absolute;}
}';
$this->assertSame($sExpected, $oDoc->__toString());
}

function parsedStructureForFile($sFileName) {
$sFile = dirname(__FILE__) . '/../../files' . DIRECTORY_SEPARATOR . "$sFileName.css";
$oParser = new Parser(file_get_contents($sFile));
Expand Down
16 changes: 16 additions & 0 deletions tests/files/comments.css
@@ -0,0 +1,16 @@
/**
* Comments Hell.
*/
@import /* Number 1 */"some/url.css"/* Number 2 */ screen/* Number 3 */;

.foo, /* Number 4 */ #bar/* Number 5 */ {
background-color/* Number 6 */: #000/* Number 7 */;
}

@media /* Number 8 */screen /* Number 9 */{
/** Number 10 **/
#foo.bar {
position: absolute;/**/
}
}
/** Number 11 **/

0 comments on commit 8b773b1

Please sign in to comment.