Skip to content

Commit

Permalink
Merge pull request #1 from wildbit/bug/invalid-css-declaration
Browse files Browse the repository at this point in the history
Fixing null reference exception for an invalid CSS rule.
  • Loading branch information
Andrew Theken authored Jan 3, 2017
2 parents 8997f7b + 6cb6347 commit 07d8d51
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 2 deletions.
8 changes: 7 additions & 1 deletion StyleMerge.Tests/InlinerTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ public void InlinerShouldNotApplyStylesToHead()
Assert.Equal(Outputs.universal_selector_doesnt_apply_to_head.EliminateWhitespace(), processed);
}


[Fact]
public void InlinerShouldProperlyHandleDoubleQuotesInDeclarations()
{
Expand All @@ -119,6 +118,13 @@ public void InlinerShouldMaintainImportantDeclarations()
Assert.Equal(Outputs.inliner_should_maintain_important_declaration.EliminateWhitespace(), processed);
}

[Fact]
public void InlinerShouldSkipInvalidCSSDeclarations()
{
var html = Inliner.ProcessHtml(Inputs.InlinerShouldSkipInvalidCSSDeclarations).EliminateWhitespace();
Assert.Equal(Outputs.Expected_InlinerShouldSkipInvalidCSSDeclarations.EliminateWhitespace(), html);
}

[Fact]
public void InlinerCanParseAndInlineEmailACIDTestCSS()
{
Expand Down
23 changes: 23 additions & 0 deletions StyleMerge.Tests/Inputs.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions StyleMerge.Tests/Inputs.resx
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,7 @@
<data name="inliner_should_maintain_important_stats" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\inliner_should_maintain_important_stats.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
</data>
<data name="InlinerShouldSkipInvalidCSSDeclarations" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\InlinerShouldSkipInvalidCSSDeclarations.html;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
</data>
</root>
18 changes: 18 additions & 0 deletions StyleMerge.Tests/Outputs.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions StyleMerge.Tests/Outputs.resx
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@
<data name="Expected_InlinerShouldKeepMediaQueryStylesInStyleBlocks" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>resources\expected_inlinershouldkeepmediaquerystylesinstyleblocks.html;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
</data>
<data name="Expected_InlinerShouldSkipInvalidCSSDeclarations" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\Expected_InlinerShouldSkipInvalidCSSDeclarations.html;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
</data>
<data name="Expected_Specificity_Ordering_Test" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>resources\expected_specificity_ordering_test.html;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>

</head>
<body>
<div style="color: #000" id="foo"></div>

</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<style>
div {
color: #000;
}

#foo
</style>
</head>
<body>
<div id="foo"></div>
</body>
</html>
2 changes: 2 additions & 0 deletions StyleMerge.Tests/StyleMerge.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@
<None Include="Resources\Inliner_Should_Support_PseudoClasses.txt" />
<None Include="Resources\inliner_should_maintain_important_stats.txt" />
<None Include="Resources\inliner_should_maintain_important_declaration.txt" />
<Content Include="Resources\Expected_InlinerShouldSkipInvalidCSSDeclarations.html" />
<Content Include="Resources\InlinerShouldSkipInvalidCSSDeclarations.html" />
<Content Include="Resources\Specificity_Ordering_Test.html" />
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion StyleMerge/Inliner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static String ProcessHtml(string sourceHtml)
{
var uninlineable = new List<Tuple<string, StyleDeclaration>>();

var styleRules = styleSheet.Item2.StyleRules.ToArray();
var styleRules = styleSheet.Item2.StyleRules.Where(s => s.Selector != null).ToArray();
foreach (var s in styleRules)
{
var selectors = s.Selector.ToString().Split(',').ToLookup(k => true);
Expand Down

0 comments on commit 07d8d51

Please sign in to comment.