Skip to content

Commit

Permalink
Merge pull request #121 from MartinWelsch/issue-120
Browse files Browse the repository at this point in the history
Escape property name
  • Loading branch information
FlorianRappl authored Nov 1, 2022
2 parents bbfba7d + 09500e0 commit 286ebaf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 22 additions & 0 deletions src/AngleSharp.Css.Tests/Library/StringRepresentation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,27 @@ public void ConicGradientNotParsedCorrectly_Issue101()
var css = styleSheet.ToCss();
Assert.AreEqual("div { background: conic-gradient(rgba(255, 0, 0, 1), rgba(255, 255, 0, 1), rgba(0, 128, 0, 1)) }", css);
}

[Test]
public void EscapePropertyNames_CustomProperty_Issue120()
{
var css = @".class { --\/\%\$\!: value }";
var styleSheet = ParseStyleSheet(css);

var generatedCss = styleSheet.ToCss();

Assert.AreEqual(css, generatedCss);
}

[Test]
public void EscapePropertyNames_UnknownDeclaration_Issue120()
{
var css = @".class { \/\%\$\!: value }";
var styleSheet = ParseStyleSheet(css, new CssParserOptions{ IsIncludingUnknownDeclarations = true });

var generatedCss = styleSheet.ToCss();

Assert.AreEqual(css, generatedCss);
}
}
}
2 changes: 1 addition & 1 deletion src/AngleSharp.Css/Dom/Internal/CssProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public Boolean IsImportant

#region String Representation

public void ToCss(TextWriter writer, IStyleFormatter formatter) => writer.Write(formatter.Declaration(Name, Value, IsImportant));
public void ToCss(TextWriter writer, IStyleFormatter formatter) => writer.Write(formatter.Declaration(CssUtilities.Escape(Name), Value, IsImportant));

#endregion
}
Expand Down

0 comments on commit 286ebaf

Please sign in to comment.