Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure window still exists before getting document #396

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
8 changes: 1 addition & 7 deletions src/dom/get_attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: <input disabled>
Expand Down
4 changes: 1 addition & 3 deletions src/dom/get_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
7 changes: 6 additions & 1 deletion src/dom/sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down