Closed nikolagava closed 1 year ago
After some digging I found the culprit.
Line 13 copiedStyle := css.CSSStyleRule{Selector: css.NewCSSValueString(selector), Styles: styles}
uses css.NewCSSValueString from your other project https://github.com/vanng822/css which escapes the CSS rule.
func NewCSSValueString(data string) *CSSValue {
data = strings.ReplaceAll(data, `\`, `\\`)
data = strings.ReplaceAll(data, `"`, `\"`)
data = `"` + data + `"`
token := scanner.Token{scanner.TokenString, data, 0, 0}
return &CSSValue{Tokens: []*scanner.Token{&token}}
}
Does this have to be changed in css project or is it possible to patch it here?
thanks @nikolagava
Please change in css-project. I wonder if it does just appear or it have been there all the time?
@vanng822 Looks like these changes were made about 2 years ago. Premailer: https://github.com/vanng822/go-premailer/commit/5392cc8aa5a3c8e7c7168bf2f900db71e1983717 CSS: https://github.com/vanng822/css/commit/6ba7c46733cdfa7f3462d2c4b4d550459eac0a4c
But, what if we used css.NewCSSValue instead of css.NewCSSValueString in copyRule function? I see that characters \
and "
are escaped. Nevertheless, all premailer tests pass with this one change.
Thanks, quite long time not working with those :-D
ok, then probably better to fix it in this repo by using your suggestion. I think it would be ok not escaping since we are not allowed remote loading of css yet.
Leftover rules for selectors which cannot be applied to elements (e.g. :hover) are escaped in resulting style.
Take the simplest HTML input file in.html
After running the Transform(), leftover rules are escaped, which makes it invalid CSS, that is, rules won't be applied to elements.
out.html (formatted for clarity)