From 8e4e9e0a13796ed9a39ebb930b0ee5e55b578b82 Mon Sep 17 00:00:00 2001 From: julien Date: Sat, 7 Oct 2023 22:55:01 +0200 Subject: [PATCH] fix: #254 The abbr tag was interpreted like the br one for innerText. --- src/nodes/html.ts | 2 +- test/tests/issues/254.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 test/tests/issues/254.js diff --git a/src/nodes/html.ts b/src/nodes/html.ts index c6d222a..a9b6b2e 100644 --- a/src/nodes/html.ts +++ b/src/nodes/html.ts @@ -249,7 +249,7 @@ export default class HTMLElement extends Node { */ public get rawText() { // https://github.com/taoqf/node-html-parser/issues/249 - if (/br/i.test(this.rawTagName)) { + if (/^br$/i.test(this.rawTagName)) { return '\n'; } return this.childNodes.reduce((pre, cur) => { diff --git a/test/tests/issues/254.js b/test/tests/issues/254.js new file mode 100644 index 0000000..de0226b --- /dev/null +++ b/test/tests/issues/254.js @@ -0,0 +1,10 @@ +const { parse } = require('@test/test-target'); + +describe('issue 254', function () { + it('abbr in innertext should not turn into \\n', function () { + const html = `
Hello World
`; + const root = parse(html); + const div = root.querySelector('div'); + div.innerText.should.eql(`Hello World`); + }); +});