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

Commit 42d24b8

Browse files
committed
Merge pull request #346 from blois/fix_textContent
Make Node.textContent ignore comment nodes
2 parents 492935d + 28da68b commit 42d24b8

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/wrappers/Node.js

+3-1
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

+12-1
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)