-
-
Notifications
You must be signed in to change notification settings - Fork 395
Open
Description
I was using v3.9 for a long time but recently decided to upgrade to the latest version (10.0). My code started to break down because I was passing Buffer to the parser.write. Following is the small reproducible code:
const { Parser } = require('htmlparser2');
const parser = new Parser({
onopentag(name, attributes) {
console.log(`Opening tag: ${name}`);
},
ontext(text) {
console.log(`Text: ${text}`);
},
onclosetag(name) {
console.log(`Closing tag: ${name}`);
},
onerror(err) {
console.error('Parser error:', err.message);
}
});
const htmlBuffer = Buffer.from('<div>Hello World</div>');
try {
console.log('Attempting to write Buffer to parser...');
parser.write(htmlBuffer);
parser.end();
} catch (error) {
console.error('Caught error:', error.message);
}
Above code returns this.buffer.charCodeAt is not a function for all versions about 8.0. For any version below 8.0, it returns ```
Opening tag: div
Text: Hello World
Closing tag: div
I don't if the change in behaviour is intentional or not. However I feel either release notes should be updated or type of the argument of the `write()` should be documented in the readme file.
Metadata
Metadata
Assignees
Labels
No labels