ershov-konst / dom-parser

Fast dom parser based on regexps
ISC License
107 stars 21 forks source link

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

Open Cheng007 opened 7 months ago

Cheng007 commented 7 months ago

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 commented 7 months ago

I submitted a PR and hope this will help

mister-teddy commented 6 months ago

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

carafelix commented 4 months ago

Same here

BernhardBehrendt commented 3 months ago

same here

lookus69 commented 1 month ago

me too! please solve this!! thanks!

jpazer commented 1 month ago

Me too!

thepeski commented 4 days ago

Same here ;)