Skip to content
This repository has been archived by the owner on Jan 27, 2021. It is now read-only.

Commit

Permalink
Fix #8
Browse files Browse the repository at this point in the history
The dynamic document we create to pre-process HTML will automatically create wrapping document, head, and body elements when HTML is passed in. This resulted in extra <head> and <body> tags getting created when calling innerHTML on elements that are not document elements.
  • Loading branch information
xirzec committed Jan 22, 2015
1 parent 61e0064 commit d04cc75
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions winstore-jscompat.js
Expand Up @@ -57,7 +57,7 @@
return isUnsafe;
}

function cleanse(html) {
function cleanse(html, isDocument) {
var cleaner = document.implementation.createHTMLDocument("cleaner");
empty(cleaner.documentElement);
MSApp.execUnsafeLocalFunction(function () {
Expand Down Expand Up @@ -120,7 +120,17 @@
}
cleanseAttributes(cleaner.documentElement);

return Array.prototype.slice.call(document.adoptNode(cleaner.documentElement).childNodes);
var rootElement;
// If we are setting inner/outerHTML on a document element grab everything.
if (isDocument) {
rootElement = cleaner.documentElement;
} else {
// Otherwise, the cleaner will dynamically create wrapping document and body tags, so take
// from inside the body.
rootElement = cleaner.body;
}

return Array.prototype.slice.call(document.adoptNode(rootElement).childNodes);
}

function cleansePropertySetter(property, setter) {
Expand All @@ -133,7 +143,7 @@
originalSetter.call(this, value);
} else {
var that = this;
var nodes = cleanse(value);
var nodes = cleanse(value, that.tagName === 'HTML');
MSApp.execUnsafeLocalFunction(function () {
setter(propertyDescriptor, that, nodes);
});
Expand Down

0 comments on commit d04cc75

Please sign in to comment.