taoqf / node-html-parser

A very fast HTML parser, generating a simplified DOM, with basic element query support.
MIT License
1.11k stars 107 forks source link

Bug: Parsing doesn't work with <script src="xx" /> in head #195

Closed mraxus closed 2 years ago

mraxus commented 2 years ago

Tested with latest 5.2.0; nodeJs v14.19.0.

When running the following example I get 0 nodes found, when in fact there is one:

const { parse: HtmlParser } = require('node-html-parser');

var ls = `<html><head><script src="js/book.js" /><meta charset="UTF-8"/></head></html>`
console.log(HtmlParser(ls).querySelectorAll('meta').length);

If I change the <script src="js/book.js" /> to <script src="js/book.js"></script> (or remove it), the code returns 1.

taoqf commented 2 years ago

script is not treated as self-cloing tag for now. I searched for the support, find this

taoqf commented 2 years ago

try v5.4.0