dom-parser icon indicating copy to clipboard operation
dom-parser copied to clipboard

TypeError: Cannot read properties of null (reading 'isSelfCloseTag')

Open Cheng007 opened this issue 1 year ago • 8 comments
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;
}

Cheng007 avatar Mar 09 '24 14:03 Cheng007

I submitted a PR and hope this will help

Cheng007 avatar Mar 11 '24 09:03 Cheng007

Please review the PR #35, folks! I'm having the same issue.

mister-teddy avatar Apr 03 '24 04:04 mister-teddy

Same here

carafelix avatar May 31 '24 05:05 carafelix

same here

BernhardBehrendt avatar Jul 07 '24 21:07 BernhardBehrendt