Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
Make Node.textContent ignore comment nodes
Browse files Browse the repository at this point in the history
Currently it is incorrectly including the text from comment nodes in generating textContent.
  • Loading branch information
blois committed Jan 14, 2014
1 parent 492935d commit 28da68b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/wrappers/Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,9 @@
// are no shadow trees below or above the context node.
var s = '';
for (var child = this.firstChild; child; child = child.nextSibling) {
s += child.textContent;
if (child.nodeType != Node.COMMENT_NODE) {
s += child.textContent;
}
}
return s;
},
Expand Down
13 changes: 12 additions & 1 deletion test/js/Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,21 @@ suite('Node', function() {
parent.insertBefore(c3);
parent.insertBefore(c2, c3);
parent.insertBefore(c1, c2);

assert.equal(parent.firstChild, c1);
assert.equal(c1.nextElementSibling, c2);
assert.equal(c2.nextElementSibling, c3);
});

test('textContent of comment', function() {
var comment = document.createComment('abc');
assert.equal(comment.textContent, 'abc');
});

test('textContent ignores comments', function() {
var div = document.createElement('div');
div.innerHTML = 'ab<!--cd-->ef';
assert.equal(div.textContent, 'abef');
});

});

0 comments on commit 28da68b

Please sign in to comment.