Open szaleq opened 2 months ago
I just experienced this bug. Is there any progress or anyone actively working on it? If not, I'd be happy to contribute a fix, however, I am new to contributing to Juice therefore I'd appreciate some guidance first. Thank you!
I use v9.1.0, and it happens for me after dependencies update, too.
Looks like the issue is in cheerio
v1.0.0. Here is the related issue: https://github.com/cheeriojs/cheerio/issues/4045
I have some HTML which is a result of other processing and already contains some inline styles. I'm then using juice to inline some global CSS, as the output must be used as an email content. I'm using Google Fonts loaded by my CMS, some of them are quoted - produced CSS looks like this:
font-family: "One Sans", sans-serif;
which is a valid CSS. When inlined into a div style attribute, it gets encoded:This causes error in Juice, as it does not decode the HTML entities and instead tries to parse it as css rules. Here are the objects from juice parsing:
And it fails with the error:
Cannot read properties of undefined (reading 'indexOf')
.Minimal reproduction
Just create an
input.html
file and paste this code:Then run:
And see the error.
Solution
Juice should decode HTML entities after reading an attribute value and before parsing it to CSS rules. This way it could convert
"
(and other such strings) back to the proper double-quote character ("
) so that it woudn't contain any semi-colons and could be properly parsed into CSS.