Skip to content

Commit 3000d9c

Browse files
committed
Fixed issue with potential null-selector #52
1 parent d4fe7b7 commit 3000d9c

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/AngleSharp.Css.Tests/Extensions/AnalysisWindow.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ namespace AngleSharp.Css.Tests.Extensions
44
using AngleSharp.Dom;
55
using NUnit.Framework;
66
using System.Text;
7+
using System.Threading.Tasks;
78
using static CssConstructionFunctions;
89

910
[TestFixture]
@@ -277,5 +278,16 @@ public void GetCascadedValueOfTextTransformFromElementStyle()
277278
Assert.IsNotNull(styleNormal);
278279
Assert.AreEqual("uppercase", styleNormal.GetTextTransform());
279280
}
281+
282+
[Test]
283+
public async Task NullSelectorStillWorks_Issue52()
284+
{
285+
var sheet = ParseStyleSheet("a {}");
286+
var document = await sheet.Context.OpenAsync(res => res.Content("<body></body>"));
287+
sheet.Add(new CssStyleRule(sheet));
288+
var sc = new StyleCollection(new[] { sheet }, new DefaultRenderDevice());
289+
var decl = sc.ComputeCascadedStyle(document.Body);
290+
Assert.IsNotNull(decl);
291+
}
280292
}
281293
}

src/AngleSharp.Css/Dom/StyleCollectionExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public static ICssStyleDeclaration ComputeCascadedStyle(this StyleCollection sty
103103
#region Helpers
104104

105105
private static IEnumerable<ICssStyleRule> SortBySpecificity(this IEnumerable<ICssStyleRule> rules, IElement element) =>
106-
rules.Where(m => m.Selector.Match(element)).OrderBy(m => m.Selector.Specificity);
106+
rules.Where(m => m.Selector?.Match(element) ?? false).OrderBy(m => m.Selector.Specificity);
107107

108108
#endregion
109109
}

0 commit comments

Comments
 (0)