From 6de54c59eec2f8c7b6b434d46def310c29b3a367 Mon Sep 17 00:00:00 2001 From: Petrik de Heus Date: Wed, 14 Nov 2018 20:31:35 +0000 Subject: [PATCH 1/2] Make sure window still exists before getting document --- src/dom/sandbox.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/dom/sandbox.js b/src/dom/sandbox.js index e750956..e7c0fbe 100644 --- a/src/dom/sandbox.js +++ b/src/dom/sandbox.js @@ -167,7 +167,12 @@ iframeDocument.close(); this.getWindow = function() { return iframe.contentWindow; }; - this.getDocument = function() { return iframe.contentWindow.document; }; + this.getDocument = function() { + var w = this.getWindow(); + if(w !== null) { + return w.document; + } + }; // Catch js errors and pass them to the parent's onerror event // addEventListener("error") doesn't work properly in some browsers From 075fc822f6584f40b25a243ada532d2bd8ab3487 Mon Sep 17 00:00:00 2001 From: Petrik Date: Sat, 22 Jun 2019 17:03:55 +0200 Subject: [PATCH 2/2] Remove code to force absolute urls Switching to view source and back again converts relative urls to absolute urls even if we want relative urls. --- src/dom/get_attribute.js | 8 +------- src/dom/get_attributes.js | 4 +--- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/dom/get_attribute.js b/src/dom/get_attribute.js index f671b5d..aad245f 100644 --- a/src/dom/get_attribute.js +++ b/src/dom/get_attribute.js @@ -12,13 +12,7 @@ wysihtml.dom.getAttribute = function(node, attributeName) { var HAS_GET_ATTRIBUTE_BUG = !wysihtml.browser.supportsGetAttributeCorrectly(); attributeName = attributeName.toLowerCase(); var nodeName = node.nodeName; - if (nodeName == "IMG" && attributeName == "src" && wysihtml.dom.isLoadedImage(node) === true) { - // Get 'src' attribute value via object property since this will always contain the - // full absolute url (http://...) - // this fixes a very annoying bug in firefox (ver 3.6 & 4) and IE 8 where images copied from the same host - // will have relative paths, which the sanitizer strips out (see attributeCheckMethods.url) - return node.src; - } else if (HAS_GET_ATTRIBUTE_BUG && "outerHTML" in node) { + if (HAS_GET_ATTRIBUTE_BUG && "outerHTML" in node) { // Don't trust getAttribute/hasAttribute in IE 6-8, instead check the element's outerHTML var outerHTML = node.outerHTML.toLowerCase(), // TODO: This might not work for attributes without value: diff --git a/src/dom/get_attributes.js b/src/dom/get_attributes.js index 54820e3..5a79da0 100644 --- a/src/dom/get_attributes.js +++ b/src/dom/get_attributes.js @@ -17,9 +17,7 @@ wysihtml.dom.getAttributes = function(node) { for (attr in node.attributes) { if ((node.attributes.hasOwnProperty && node.attributes.hasOwnProperty(attr)) || (!node.attributes.hasOwnProperty && Object.prototype.hasOwnProperty.call(node.attributes, attr))) { if (node.attributes[attr].specified) { - if (nodeName == "IMG" && node.attributes[attr].name.toLowerCase() == "src" && wysihtml.dom.isLoadedImage(node) === true) { - attributes['src'] = node.src; - } else if (wysihtml.lang.array(['rowspan', 'colspan']).contains(node.attributes[attr].name.toLowerCase()) && HAS_GET_ATTRIBUTE_BUG) { + if (wysihtml.lang.array(['rowspan', 'colspan']).contains(node.attributes[attr].name.toLowerCase()) && HAS_GET_ATTRIBUTE_BUG) { if (node.attributes[attr].value !== 1) { attributes[node.attributes[attr].name] = node.attributes[attr].value; }