forked from ashi009/node-fast-html-parser
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Preserve invalid nested A tags in AST (see #215 for detail)
- Loading branch information
Showing
4 changed files
with
109 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# These settings are for any web project | ||
|
||
# Handle line endings automatically for files detected as text | ||
# and leave all files detected as binary untouched. | ||
* text=auto | ||
|
||
# Force the following filetypes to have unix eols, so Windows does not break them | ||
*.* text eol=lf | ||
|
||
# Windows forced line-endings | ||
/.idea/* text eol=crlf | ||
|
||
# | ||
## These files are binary and should be left untouched | ||
# | ||
|
||
# (binary is a macro for -text -diff) | ||
*.png binary | ||
*.jpg binary | ||
*.jpeg binary | ||
*.gif binary | ||
*.ico binary | ||
*.mov binary | ||
*.mp4 binary | ||
*.mp3 binary | ||
*.flv binary | ||
*.fla binary | ||
*.swf binary | ||
*.gz binary | ||
*.zip binary | ||
*.7z binary | ||
*.ttf binary | ||
*.eot binary | ||
*.woff binary | ||
*.pyc binary | ||
*.pdf binary | ||
*.ez binary | ||
*.bz2 binary | ||
*.swp binary |
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
const { parse, NodeType } = require('@test/test-target'); | ||
|
||
describe('Nested A Tags', function () { | ||
it('Tags preserved by default', function () { | ||
const html = `<A href="#"><b>link <a href="#">nested link</a> end</b></A>`; | ||
|
||
const root = parse(html); | ||
|
||
root.innerHTML.should.eql(`<A href="#"><b>link <a href="#">nested link</a> end</b></A>`); | ||
root.childNodes.length.should.eql(1); | ||
|
||
const a1 = root.childNodes[0]; | ||
a1.tagName.should.eql('A'); | ||
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(3); | ||
b.text.should.eql('link nested link end'); | ||
|
||
const a2 = b.childNodes[1]; | ||
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 = b.childNodes[2]; | ||
endText.nodeType.should.eql(NodeType.TEXT_NODE); | ||
endText.textContent.should.eql(' end'); | ||
}); | ||
|
||
it('Tags fixed with fixNestedATags option', function () { | ||
const html = `<A href="#"><b>link <a href="#">nested link</a> end</b></A>`; | ||
|
||
const root = parse(html, { fixNestedATags: true }); | ||
|
||
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(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.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'); | ||
}); | ||
}); |