dom-parser
dom-parser copied to clipboard
TypeError: Cannot read properties of null (reading 'isSelfCloseTag')
trafficstars
There is an error TypeError: Cannot read properties of null (reading 'isSelfCloseTag') while parsing from the following html string:
const htmlString = `<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Webpack App</title>
<meta name="viewport" content="width=device-width, initial-scale=1"><script defer src="main.bundle.js"></script></head>
<body>
</body>
</html>`;
It directly caused by the following unhandled null input element
function isElementComposed(element, tag) {
if (!tag) {
return false;
}
const isCloseTag = closeTagExp.test(tag);
const [, nodeName] = tag.match(nodeNameExp) || [];
const isElementClosedByTag = isCloseTag && element.nodeName === nodeName;
return isElementClosedByTag || element.isSelfCloseTag || element.nodeType === Node_1.NodeType.text;
}
I submitted a PR and hope this will help
Please review the PR #35, folks! I'm having the same issue.
Same here
same here