fix: reject loadImage when src is null or invalid#2518
Merged
chearon merged 1 commit intoAutomattic:masterfrom Sep 7, 2025
Merged
fix: reject loadImage when src is null or invalid#2518chearon merged 1 commit intoAutomattic:masterfrom
chearon merged 1 commit intoAutomattic:masterfrom
Conversation
|
I'm also encountering this issue. I hope it can be merged. |
cf6b80f to
ecd20bd
Compare
chearon
reviewed
Aug 17, 2025
index.js
Outdated
| function loadImage (src) { | ||
| return new Promise((resolve, reject) => { | ||
| if (!src) return reject(new Error("Invalid image source")); | ||
|
|
Collaborator
There was a problem hiding this comment.
This can be placed in a final else branch on line 66 of lib/image.js to fix the whole class of bugs. It isn't just null/undefined that will cause onload to not be called. Then you could mark this as fixes #2525 as well.
Contributor
Author
There was a problem hiding this comment.
Hi @chearon ,
Thanks for the review.
Would you prefer having the check in both index.js and image.js or only in the image.js ?
ecd20bd to
6186db2
Compare
Contributor
Author
|
Hi @chearon , Ian |
6186db2 to
3f92b48
Compare
chearon
approved these changes
Sep 7, 2025
Collaborator
chearon
left a comment
There was a problem hiding this comment.
Great, thanks. I just added the issue # to the changelog.
Description:
- To handle non-string/non-Buffer sources while fetching image.
- Add test cases for '', null, and undefined inputs to loadImage()
Test Result:
```
npm run test
...
✔ rejects when loadImage is called with null
✔ rejects when loadImage is called with undefined
✔ rejects when loadImage is called with empty string
291 passing (302ms)
6 pending
```
3f92b48 to
3fe2c56
Compare
Collaborator
|
...and fixed conflicts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix: reject loadImage when src is null or invalid
Description:
Test Result:
Thanks for contributing!
Fix #2304