Skip to content

Commit

Permalink
Merge pull request #161 from inforithmics/FixEndlessLoop
Browse files Browse the repository at this point in the history
Fix endless loop
  • Loading branch information
TylerBrinks committed Aug 31, 2023
2 parents 41dc288 + 2cf0965 commit 1803173
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/ExCSS.Tests/ExCSS.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
<PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0" />
<PackageReference Include="xunit" Version="2.5.0" />
</ItemGroup>

<ItemGroup>
Expand Down
49 changes: 49 additions & 0 deletions src/ExCSS.Tests/Sheet.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Threading;

namespace ExCSS.Tests
{
Expand Down Expand Up @@ -920,6 +921,54 @@ public void CssParseSheetWithTwoStyleAndMediaRule()
Assert.Equal(RuleType.Media, sheet.Rules[2].Type);
}

[Fact(Timeout = 1000)]
public void CssParseSheetWithAtAndCommentDoesNotTakeForever()
{
var sheet = ParseStyleSheet(@"
h3 {color: yellow;
@media print {
h3 {color: black; }
}
");
Assert.Equal(1, sheet.Rules.Length);
Assert.Equal(RuleType.Style, sheet.Rules[0].Type);
}

[Fact(Timeout = 1000)]
public void CssParseSheetWithAtAndCommentDoesNotTakeForever2()
{
var sheet = ParseStyleSheet(@"
:root {
--layout: {
}
--layout-horizontal: {
@apply (--layout);
}
}");
Assert.Equal(1, sheet.Rules.Length);
Assert.Equal(RuleType.Style, sheet.Rules[0].Type);
}

[Fact(Timeout = 1000)]
public void CssParseSheetWithAtAndCommentDoesNotTakeForever3()
{
var sheet = ParseStyleSheet( @"
@media (max-width: 991px) {
body {
background-color: #013668;
}
;
}
@media (max-width: 991px) {
body {
background: #FFF;
}
}");
Assert.Equal(1, sheet.Rules.Length);
Assert.Equal(RuleType.Media, sheet.Rules[0].Type);
}

[Fact]
public void CssParseImportStatementWithNoMediaTextFollowedByStyle()
{
Expand Down
5 changes: 5 additions & 0 deletions src/ExCSS/Parser/StylesheetComposer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,11 @@ public TextPosition FillDeclarations(StyleDeclaration style)
parentPageRule.AppendChild(marginStyle);
token = marginToken;
}
else
{
// Advance to the next token or this is an endless loop
token = _lexer.Get();
}
}
else
{
Expand Down

0 comments on commit 1803173

Please sign in to comment.