Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/browser/domUtility.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function treeToArray(elem) {
var nextDescription;
for (var height = 0; elem && height < MAX_HEIGHT; height++) {
nextDescription = describeElement(elem);
if (nextDescription.tagName === 'html') {
if (!nextDescription || nextDescription.tagName === 'html') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!nextDescription || nextDescription.tagName === 'html') {
if (nextDescription == null || nextDescription.tagName?.toLowerCase() === 'html') {

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need the ? if it's null? The code in describeElement looks like it reliably sets a tagname if not. It also already calls toLowerCase() when setting it.

Just being extra defensive?

break;
}
out.unshift(nextDescription);
Expand Down
5 changes: 5 additions & 0 deletions test/browser.domUtility.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ describe('treeToArray', function () {
var arr = d.treeToArray(e1);
expect(arr.length).to.eql(5);
});
it('should handle elements without tag names', function () {
var e1 = genElement(null);
var arr = d.treeToArray(e1);
expect(arr).to.eql([]);
});
it('should put the innermost element last', function () {
var e1 = genElement('div', 'id1');
var e2 = genElement('div', 'id2', 'a b');
Expand Down