diff --git a/src/nodes/html.ts b/src/nodes/html.ts index 0a0dbc8..9cfd39e 100644 --- a/src/nodes/html.ts +++ b/src/nodes/html.ts @@ -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; diff --git a/test/144.js b/test/144.js new file mode 100644 index 0000000..ace91e1 --- /dev/null +++ b/test/144.js @@ -0,0 +1,18 @@ +const { parse } = require('../dist'); + +describe('issue 144', function () { + it('Nested A tags parsed improperly', function () { + const html = `link nested link end`; + const root = parse(html); + root.innerHTML.should.eql(`link nested link 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'); + }); +});