From acb31ab4fad437ff33c7bb6b4e00e97c51328ee0 Mon Sep 17 00:00:00 2001 From: taoqf Date: Tue, 6 Apr 2021 10:43:36 +0800 Subject: [PATCH] fix: issue #109 --- src/nodes/html.ts | 2 +- test/109.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 test/109.js diff --git a/src/nodes/html.ts b/src/nodes/html.ts index a7a9784..2215a1d 100644 --- a/src/nodes/html.ts +++ b/src/nodes/html.ts @@ -269,7 +269,7 @@ export default class HTMLElement extends Node { if (tag) { // const void_tags = new Set('area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr'.split('|')); // const is_void = void_tags.has(tag); - const is_void = /area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr/i.test(tag); + const is_void = /^(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/i.test(tag); const attrs = this.rawAttrs ? ` ${this.rawAttrs}` : ''; if (is_void) { return `<${tag}${attrs}>`; diff --git a/test/109.js b/test/109.js new file mode 100644 index 0000000..084e9e3 --- /dev/null +++ b/test/109.js @@ -0,0 +1,14 @@ +const { parse } = require('../dist'); + +describe('self-close tag', function () { + it('should not teat textarea as self-colse tag', async function () { + const html = ''; + const root = parse(html); + root.toString().should.eql(html); + }); + it('inptu is self-closing', async function () { + const html = ''; + const root = parse(html); + root.toString().should.eql(''); + }); +});