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

Shouldn't try to load image with removed src attribute #2150

Closed
atsikov opened this issue Feb 13, 2018 · 0 comments
Closed

Shouldn't try to load image with removed src attribute #2150

atsikov opened this issue Feb 13, 2018 · 0 comments

Comments

@atsikov
Copy link
Contributor

atsikov commented Feb 13, 2018

Basic info:

  • Node.js version: 9.5
  • jsdom version: 11.6.2

Minimal reproduction case

const { JSDOM } = require("jsdom");
const dom = new JSDOM(
    "<!DOCTYPE html>",
    {
        resources: "usable",
    },
);

const grayPx = "data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==";
const image = new dom.window.Image();
const onLoad = () => {
    console.log("image loaded");
    image.removeEventListener("load", onLoad);
    image.removeAttribute("src");
}
image.addEventListener("load", onLoad);
image.src = grayPx;

This code causes an exception. JSDOM is trying to load image with null url.

image loaded, will try to remove src attribute
=====
Error: Uncaught [TypeError: Cannot read property 'replace' of null]
    at reportException (node_modules/jsdom/lib/jsdom/living/helpers/runtime-script-errors.js:63:24)
    at invokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:233:9)
    at HTMLImageElementImpl._dispatch (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:122:9)
    at HTMLImageElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:83:17)
    at HTMLImageElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/nodes/HTMLElement-impl.js:40:27)
    at node_modules/jsdom/lib/jsdom/browser/resource-loader.js:51:15
    at Object.check (node_modules/jsdom/lib/jsdom/living/nodes/Document-impl.js:91:11)
    at node_modules/jsdom/lib/jsdom/living/nodes/Document-impl.js:110:12
    at wrappedEnqueued (node_modules/jsdom/lib/jsdom/browser/resource-loader.js:255:16)
    at readDataUrl (node_modules/jsdom/lib/jsdom/browser/resource-loader.js:114:7)

TypeError: Cannot read property 'replace' of null
    at fetch (node_modules/jsdom/lib/jsdom/browser/resource-loader.js:139:6)
    at Object.exports.load (node_modules/jsdom/lib/jsdom/browser/resource-loader.js:270:11)
    at HTMLImageElementImpl._attrModified (jsdom/lib/jsdom/living/nodes/HTMLImageElement-impl.js:23:24)
    at Object.exports.removeAttribute (node_modules/jsdom/lib/jsdom/living/attributes.js:242:15)
    at Object.exports.removeAttributeByName (node_modules/jsdom/lib/jsdom/living/attributes.js:392:13)
    at HTMLImageElementImpl.removeAttribute (node_modules/jsdom/lib/jsdom/living/nodes/Element-impl.js:257:16)
    at HTMLImageElement.removeAttribute (node_modules/jsdom/lib/jsdom/living/generated/Element.js:163:21)
    at HTMLImageElement.onLoad (test-jsdom-image.js:15:11)
    at invokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:217:27)
    at HTMLImageElementImpl._dispatch (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:122:9)

How does similar code behave in browsers?

There are no remote requests for null resource. Also no exceptions are thrown.
http://jsbin.com/dehiweqape/edit?html,output

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant