forked from ashi009/node-fast-html-parser
-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #148 from nonara/fix-144
Fix 144
- Loading branch information
Showing
2 changed files
with
33 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,34 @@ | ||
const { parse } = require('../dist'); | ||
const { parse, NodeType } = require('../dist'); | ||
|
||
// Also see comments on https://github.com/taoqf/node-html-parser/pull/148 for additional issues corrected | ||
describe('issue 144', function () { | ||
it('Nested A tags parsed improperly', function () { | ||
const html = `<a href="#">link <a href="#">nested link</a> end</a>`; | ||
const html = `<A href="#"><b>link <a href="#">nested link</a> end</b></A>`; | ||
|
||
const root = parse(html); | ||
root.innerHTML.should.eql(`<a href="#">link </a><a href="#">nested link</a> end`); | ||
|
||
root.innerHTML.should.eql(`<A href="#"><b>link </b></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); | ||
a1.nodeType.should.eql(NodeType.ELEMENT_NODE); | ||
a1.childNodes.length.should.eql(1); | ||
|
||
const b = a1.childNodes[0]; | ||
b.tagName.should.eql('B'); | ||
b.childNodes.length.should.eql(1); | ||
b.text.should.eql('link '); | ||
|
||
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'); | ||
a2.tagName.should.eql('A'); | ||
a2.nodeType.should.eql(NodeType.ELEMENT_NODE); | ||
a2.childNodes.length.should.eql(1); | ||
a2.childNodes[0].nodeType.should.eql(NodeType.TEXT_NODE); | ||
a2.text.should.eql('nested link'); | ||
|
||
const endText = root.childNodes[2]; | ||
endText.nodeType.should.eql(NodeType.TEXT_NODE); | ||
endText.textContent.should.eql(' end'); | ||
}); | ||
}); |