You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
<!DOCTYPE html><htmllang="en"><head><style>
div {
background-color: #fff;
}
</style></head><body><divstyle="font-family:"Open Sans", sans-serif;"></div></body></html>
Then run:
npm run juice input.html output.html
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.
The text was updated successfully, but these errors were encountered:
szaleq
changed the title
Error then encoded quotes used in html attribute
Error when encoded quotes are used in html attribute
Jul 19, 2024
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 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.The text was updated successfully, but these errors were encountered: