Skip to content

Commit

Permalink
fix issue #144
Browse files Browse the repository at this point in the history
  • Loading branch information
taoqf committed Aug 28, 2021
1 parent f6d406c commit 5ccddc7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/nodes/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,13 @@ export function base_parse(data: string, options = { lowerCaseTagName: false, co
}
}

// console.error('111111111111111111', currentParent.rawTagName);
// console.error('22222222222222222222', match);
if (currentParent.rawTagName === 'a' && match[2] === 'a') {
stack.pop();
currentParent = arr_back(stack);
}

const tagEndPos = kMarkupPattern.lastIndex;
const tagStartPos = tagEndPos - match[0].length;

Expand Down
18 changes: 18 additions & 0 deletions test/144.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const { parse } = require('../dist');

describe('issue 144', function () {
it('Nested A tags parsed improperly', function () {
const html = `<a href="#">link <a href="#">nested link</a> end</a>`;
const root = parse(html);
root.innerHTML.should.eql(`<a href="#">link </a><a href="#">nested link</a> end`);
root.childNodes.length.should.eql(3);
const a1 = root.childNodes[0];
a1.tagName.should.eql('A');
a1.nodeType.should.eql(1);
const a2 = root.childNodes[1];
a2.nodeType.should.eql(1);
const t1 = root.childNodes[2];
t1.nodeType.should.eql(3);
t1.textContent.should.eql(' end');
});
});

0 comments on commit 5ccddc7

Please sign in to comment.