Skip to content

Commit 9d5f104

Browse files
committed
nicer error reporting when svg width/height missing
1 parent d24a127 commit 9d5f104

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/Image.cc

+5
Original file line numberDiff line numberDiff line change
@@ -1482,6 +1482,11 @@ Image::loadSVGFromBuffer(uint8_t *buf, unsigned len) {
14821482
width = naturalWidth = d_width;
14831483
height = naturalHeight = d_height;
14841484

1485+
if (width <= 0 || height <= 0) {
1486+
this->errorInfo.set("Width and height must be set on the svg element");
1487+
return CAIRO_STATUS_READ_ERROR;
1488+
}
1489+
14851490
return renderSVGToSurface();
14861491
}
14871492

test/canvas.test.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -2516,10 +2516,17 @@ describe('Canvas', function () {
25162516

25172517
describe('loadImage', function () {
25182518
it('doesn\'t crash when you don\'t specify width and height', async function () {
2519+
const err = {name: "Error"};
2520+
2521+
// TODO: remove this when we have a static build or something
2522+
if (os.platform() !== 'win32') {
2523+
err.message = "Width and height must be set on the svg element";
2524+
}
2525+
25192526
await assert.rejects(async () => {
25202527
const svg = `<svg xmlns="http://www.w3.org/2000/svg"><path d="M1,1"/></svg>`;
25212528
await loadImage(Buffer.from(svg));
2522-
});
2529+
}, err);
25232530
});
25242531
});
25252532
})

0 commit comments

Comments
 (0)