Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ project adheres to [Semantic Versioning](http://semver.org/).
### Added
### Fixed
* `roundRect()` shape incorrect when radii were large relative to rectangle size (#2400)
* Reject loadImage when src is null or invalid (#2304)

3.2.0
==================
Expand Down
4 changes: 4 additions & 0 deletions lib/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ Object.defineProperty(Image.prototype, 'src', {
}
} else if (Buffer.isBuffer(val)) {
setSource(this, val)
} else {
const err = new Error("Invalid image source")
if (typeof this.onerror === 'function') this.onerror(err)
else throw err
}
},

Expand Down
18 changes: 18 additions & 0 deletions test/image.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,24 @@ describe('Image', function () {
img.src = path.join(bmpDir, 'bomb.bmp')
})

it('rejects when loadImage is called with null', async function () {
await assert.rejects(
loadImage(null),
)
})

it('rejects when loadImage is called with undefined', async function () {
await assert.rejects(
loadImage(undefined),
)
})

it('rejects when loadImage is called with empty string', async function () {
await assert.rejects(
loadImage(''),
)
})

function testImgd (img, data) {
const ctx = createCanvas(img.width, img.height).getContext('2d')
ctx.drawImage(img, 0, 0)
Expand Down
Loading