Skip to content

Commit 2cf0965

Browse files
committed
Fixing Endless Parsing
1 parent 1b2a7dd commit 2cf0965

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

src/ExCSS.Tests/Sheet.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Threading;
23

34
namespace ExCSS.Tests
45
{
@@ -920,6 +921,54 @@ public void CssParseSheetWithTwoStyleAndMediaRule()
920921
Assert.Equal(RuleType.Media, sheet.Rules[2].Type);
921922
}
922923

924+
[Fact(Timeout = 1000)]
925+
public void CssParseSheetWithAtAndCommentDoesNotTakeForever()
926+
{
927+
var sheet = ParseStyleSheet(@"
928+
h3 {color: yellow;
929+
@media print {
930+
h3 {color: black; }
931+
}
932+
");
933+
Assert.Equal(1, sheet.Rules.Length);
934+
Assert.Equal(RuleType.Style, sheet.Rules[0].Type);
935+
}
936+
937+
[Fact(Timeout = 1000)]
938+
public void CssParseSheetWithAtAndCommentDoesNotTakeForever2()
939+
{
940+
var sheet = ParseStyleSheet(@"
941+
:root {
942+
--layout: {
943+
}
944+
--layout-horizontal: {
945+
@apply (--layout);
946+
}
947+
}");
948+
Assert.Equal(1, sheet.Rules.Length);
949+
Assert.Equal(RuleType.Style, sheet.Rules[0].Type);
950+
}
951+
952+
[Fact(Timeout = 1000)]
953+
public void CssParseSheetWithAtAndCommentDoesNotTakeForever3()
954+
{
955+
var sheet = ParseStyleSheet( @"
956+
@media (max-width: 991px) {
957+
body {
958+
background-color: #013668;
959+
}
960+
;
961+
}
962+
963+
@media (max-width: 991px) {
964+
body {
965+
background: #FFF;
966+
}
967+
}");
968+
Assert.Equal(1, sheet.Rules.Length);
969+
Assert.Equal(RuleType.Media, sheet.Rules[0].Type);
970+
}
971+
923972
[Fact]
924973
public void CssParseImportStatementWithNoMediaTextFollowedByStyle()
925974
{

src/ExCSS/Parser/StylesheetComposer.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,11 @@ public TextPosition FillDeclarations(StyleDeclaration style)
551551
parentPageRule.AppendChild(marginStyle);
552552
token = marginToken;
553553
}
554+
else
555+
{
556+
// Advance to the next token or this is an endless loop
557+
token = _lexer.Get();
558+
}
554559
}
555560
else
556561
{

0 commit comments

Comments
 (0)