Skip to content

Commit 5a44c8f

Browse files
committed
Accommodate uppercase A tag name
1 parent 3539fe2 commit 5a44c8f

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/nodes/html.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,7 @@ export function base_parse(data: string, options = { lowerCaseTagName: false, co
10831083
}
10841084

10851085
// Prevent nested A tags by terminating the last A and starting a new one : see issue #144
1086-
if (match[2] === 'a') {
1086+
if (match[2] === 'a' || match[2] === 'A') {
10871087
if (noNestedTagIndex !== undefined) {
10881088
stack.splice(noNestedTagIndex);
10891089
currentParent = arr_back(stack);
@@ -1128,7 +1128,7 @@ export function base_parse(data: string, options = { lowerCaseTagName: false, co
11281128
// Handle closing tags or self-closed elements (ie </tag> or <br>)
11291129
if (match[1] || match[4] || kSelfClosingElements[match[2]]) {
11301130
while (true) {
1131-
if (match[2] === 'a') noNestedTagIndex = undefined;
1131+
if (match[2] === 'a' || match[2] === 'A') noNestedTagIndex = undefined;
11321132
if (currentParent.rawTagName === match[2]) {
11331133
// Update range end for closed tag
11341134
(<[number, number]>currentParent.range)[1] = createRange(-1, Math.max(lastTextPos, tagEndPos))[1];

test/144.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
const { parse, NodeType } = require('../dist');
22

3+
// Also see comments on https://github.com/taoqf/node-html-parser/pull/148 for additional issues corrected
34
describe('issue 144', function () {
45
it('Nested A tags parsed improperly', function () {
5-
const html = `<a href="#"><b>link <a href="#">nested link</a> end</b></a>`;
6+
const html = `<A href="#"><b>link <a href="#">nested link</a> end</b></A>`;
67

78
const root = parse(html);
89

9-
root.innerHTML.should.eql(`<a href="#"><b>link </b></a><a href="#">nested link</a> end`);
10+
root.innerHTML.should.eql(`<A href="#"><b>link </b></A><a href="#">nested link</a> end`);
1011
root.childNodes.length.should.eql(3);
1112

1213
const a1 = root.childNodes[0];

0 commit comments

Comments
 (0)