AngleSharp / AngleSharp.Css

:angel: Library to enable support for cascading stylesheets in AngleSharp.
https://anglesharp.github.io
MIT License
72 stars 34 forks source link

`ToCss` returns unescaped property names #120

Closed MartinWelsch closed 1 year ago

MartinWelsch commented 1 year ago

Bug Report

Prerequisites

For more information, see the CONTRIBUTING guide.

Description

Consider the followig program:

using System;
using AngleSharp;
using AngleSharp.Css.Parser;

public class Program
{
    public static void Main()
    {
        const string stylesheetText = @".className { --\/prop: value; }";
        var parser = new CssParser();
        var style = parser.ParseStyleSheet(stylesheetText);

        Console.WriteLine(style.ToCss());
        // prints:
        // .className { --/prop: value }
    }
}

The property named --/prop is written literally which results in invalid CSS.

Expected behavior: style.ToCss() to return .className { --\/prop: value }

Actual behavior: style.ToCss() returned .className { --/prop: value }

Environment details: .NET6, AngleSharp.Css 0.16.4

Possible Solution

CssProperty should escape Name using CssUtilities.Escape(Name)