diff --git a/src/nodes/html.ts b/src/nodes/html.ts
index 13ccde7..0d89d64 100644
--- a/src/nodes/html.ts
+++ b/src/nodes/html.ts
@@ -1019,8 +1019,8 @@ export function base_parse(data: string, options = { lowerCaseTagName: false, co
pre: true,
};
const element_names = Object.keys(elements);
- const kBlockTextElements = element_names.map((it) => new RegExp(it, 'i'));
- const kIgnoreElements = element_names.filter((it) => elements[it]).map((it) => new RegExp(it, 'i'));
+ const kBlockTextElements = element_names.map((it) => new RegExp(`^${it}$`, 'i'));
+ const kIgnoreElements = element_names.filter((it) => elements[it]).map((it) => new RegExp(`^${it}$`, 'i'));
function element_should_be_ignore(tag: string) {
return kIgnoreElements.some((it) => it.test(tag));
diff --git a/test/pre.js b/test/pre.js
index 8ea275d..34a6db1 100644
--- a/test/pre.js
+++ b/test/pre.js
@@ -1,4 +1,5 @@
const { parse } = require('../dist');
+const { HTMLElement } = require('../dist');
// https://github.com/taoqf/node-html-parser/issues/77
describe('pre tag', function () {
@@ -51,4 +52,10 @@ describe('pre tag', function () {
const code = pre.firstChild;
code.childNodes.length.should.eql(11);
});
+ // see: https://github.com/taoqf/node-html-parser/issues/156
+ it('does not treat pre* tag as pre (partial match)', () => {
+ const docRoot = parse("Red");
+ Object.getPrototypeOf(docRoot.firstChild.firstChild).should.eql(HTMLElement.prototype);
+ docRoot.firstChild.firstChild.tagName.should.eql('COLOR');
+ })
});