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

Add error message when trying to use SVG in image source #7313

Merged
merged 4 commits into from
Sep 24, 2018

Conversation

ryanhamley
Copy link
Contributor

Launch Checklist

  • briefly describe the changes in this PR
  • manually test the debug page

Fixes #7312
Superseding #5240

#5240 is out of date and it's easier just to open a new one and close that. JSDom still does not implement URL.createObjectURL or URL.revokeObjectURL so there's not a good way to add a test for this. It's pretty simple though and worked as expected in manual debugging so I think no test is fine.

src/util/ajax.js Outdated
@@ -158,10 +158,15 @@ export const getImage = function(requestParameters: RequestParameters, callback:
} else if (imgData) {
const img: HTMLImageElement = new window.Image();
const URL = window.URL || window.webkitURL;
console.log('get image', imgData);
Copy link
Member

Choose a reason for hiding this comment

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

Leftover console.log

src/util/ajax.js Outdated
img.onerror = () => {
const err = new Error('Image sources cannot use SVG files');
callback(err);
};
Copy link
Member

Choose a reason for hiding this comment

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

Maybe let's do a shorter version?

img.onerror = () => callback(new Error('Image sources cannot use SVG files'));

src/util/ajax.js Outdated
@@ -162,6 +162,7 @@ export const getImage = function(requestParameters: RequestParameters, callback:
callback(null, img);
URL.revokeObjectURL(img.src);
};
img.onerror = () => callback(new Error('Image sources cannot use SVG files'));
Copy link
Contributor

Choose a reason for hiding this comment

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

Aren't there other possible reasons for an error here? There's no check that it was actually passed an SVG to begin with. Maybe something more general like 'Unable to load image. Please make sure you're using a supported image type like PNG or JPEG. SVGs are not supported' ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that's a good point. I'll update the error message.

Copy link
Contributor

@mollymerp mollymerp left a comment

Choose a reason for hiding this comment

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

ty!

@ryanhamley ryanhamley merged commit beeb173 into master Sep 24, 2018
@ryanhamley ryanhamley deleted the img-svg-error branch September 24, 2018 22:07
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

Successfully merging this pull request may close these issues.

getImage will fail silently if an SVG is requested
3 participants