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

Commit 28da68b

Browse files
author
Pete Blois
committed
Make Node.textContent ignore comment nodes
Currently it is incorrectly including the text from comment nodes in generating textContent.
1 parent 492935d commit 28da68b

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

src/wrappers/Node.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,9 @@
543543
// are no shadow trees below or above the context node.
544544
var s = '';
545545
for (var child = this.firstChild; child; child = child.nextSibling) {
546-
s += child.textContent;
546+
if (child.nodeType != Node.COMMENT_NODE) {
547+
s += child.textContent;
548+
}
547549
}
548550
return s;
549551
},

test/js/Node.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,21 @@ suite('Node', function() {
298298
parent.insertBefore(c3);
299299
parent.insertBefore(c2, c3);
300300
parent.insertBefore(c1, c2);
301-
301+
302302
assert.equal(parent.firstChild, c1);
303303
assert.equal(c1.nextElementSibling, c2);
304304
assert.equal(c2.nextElementSibling, c3);
305305
});
306306

307+
test('textContent of comment', function() {
308+
var comment = document.createComment('abc');
309+
assert.equal(comment.textContent, 'abc');
310+
});
311+
312+
test('textContent ignores comments', function() {
313+
var div = document.createElement('div');
314+
div.innerHTML = 'ab<!--cd-->ef';
315+
assert.equal(div.textContent, 'abef');
316+
});
317+
307318
});

0 commit comments

Comments
 (0)