Skip to content

Commit 1803173

Browse files
authored
Merge pull request #161 from inforithmics/FixEndlessLoop
Fix endless loop
2 parents 41dc288 + 2cf0965 commit 1803173

File tree

3 files changed

+57
-3
lines changed

3 files changed

+57
-3
lines changed

src/ExCSS.Tests/ExCSS.Tests.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
</ItemGroup>
1818

1919
<ItemGroup>
20-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
21-
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
22-
<PackageReference Include="xunit" Version="2.2.0" />
20+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
21+
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0" />
22+
<PackageReference Include="xunit" Version="2.5.0" />
2323
</ItemGroup>
2424

2525
<ItemGroup>

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)