Hello, we use juice to parse incoming emails and recently we got an email that causes juice to crash without any chance to catch the error. We narrowed it down to a simple example that gives the following error:
(node:53511) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'match' of undefined
at addProps (/private/tmp/node_modules/juice/lib/inline.js:205:35)
at Element.<anonymous> (/private/tmp/node_modules/juice/lib/inline.js:231:7)
at LoadedCheerio.each (/private/tmp/node_modules/cheerio/lib/api/traversing.js:480:26)
at handleRule (/private/tmp/node_modules/juice/lib/inline.js:120:9)
at Array.forEach (<anonymous>)
at inlineDocument (/private/tmp/node_modules/juice/lib/inline.js:36:9)
at juiceDocument (/private/tmp/node_modules/juice/lib/inline.js:459:3)
at module.exports (/private/tmp/node_modules/juice/lib/cheerio.js:61:22)
at onInline (/private/tmp/node_modules/juice/index.js:75:7)
at /private/tmp/node_modules/web-resource-inliner/src/html.js:281:13
The callback is never called and try/catch can't catch the error either. The code to reproduce:
const juice = require('juice')
function main() {
const input = `<html>
<head>
<style type="text/css">
.logo img {
.snippet {
padding: 20px 0px 5px 0px;
font-size: 0;
line-height: 0;
}
</style>
</head>
<body>
<div class="logo">
<img src="https://example.com" />
</div>
</body>
</html>`
try {
juice.juiceResources(
input,
{
webResources: {
scripts: false,
images: false,
svgs: false,
links: true,
},
},
async (err, html) => {
console.log(`juice results: ${err}, ${html} `)
},
);
} catch (err) {
console.log(`trycatch error: ${err}`)
}
}
main()
node: v14.18.1
juice: 8.0.0
Hello, we use juice to parse incoming emails and recently we got an email that causes juice to crash without any chance to catch the error. We narrowed it down to a simple example that gives the following error:
The callback is never called and try/catch can't catch the error either. The code to reproduce:
node: v14.18.1
juice: 8.0.0