Skip to content

Commit c48cd0d

Browse files
committed
Add missing null checks for CssData
1 parent 4c6e252 commit c48cd0d

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

Source/HtmlRenderer/Core/Utils/DomUtils.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,8 @@ private static void WriteHtmlTag(CssParser cssParser, StringBuilder sb, CssBox b
789789

790790
// collect all element style properties including from stylesheet
791791
var tagStyles = new Dictionary<string, string>();
792-
var tagCssBlock = box.HtmlContainer.CssData.GetCssBlock(box.HtmlTag.Name);
792+
var cssData = box.HtmlContainer.CssData;
793+
var tagCssBlock = cssData != null ? cssData.GetCssBlock(box.HtmlTag.Name) : null;
793794
if (tagCssBlock != null)
794795
{
795796
// TODO:a handle selectors
@@ -807,14 +808,17 @@ private static void WriteHtmlTag(CssParser cssParser, StringBuilder sb, CssBox b
807808
if (styleGen == HtmlGenerationStyle.Inline && att.Key == HtmlConstants.Style)
808809
{
809810
// if inline style add the styles to the collection
810-
var block = cssParser.ParseCssBlock(box.HtmlTag.Name, box.HtmlTag.TryGetAttribute("style"));
811-
foreach (var prop in block.Properties)
812-
tagStyles[prop.Key] = prop.Value;
811+
var block = cssParser != null ? cssParser.ParseCssBlock(box.HtmlTag.Name, box.HtmlTag.TryGetAttribute("style")) : null;
812+
if (block != null)
813+
{
814+
foreach (var prop in block.Properties)
815+
tagStyles[prop.Key] = prop.Value;
816+
}
813817
}
814818
else if (styleGen == HtmlGenerationStyle.Inline && att.Key == HtmlConstants.Class)
815819
{
816820
// if inline style convert the style class to actual properties and add to collection
817-
var cssBlocks = box.HtmlContainer.CssData.GetCssBlock("." + att.Value);
821+
var cssBlocks = cssData != null ? cssData.GetCssBlock("." + att.Value) : null;
818822
if (cssBlocks != null)
819823
{
820824
// TODO:a handle selectors

0 commit comments

Comments
 (0)