Skip to content

Commit cb592ce

Browse files
committedMar 18, 2021
Tests: add case for SVG with truncated embedded PNG
1 parent d69c58a commit cb592ce

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed
 

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
"install": "(node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)",
8181
"clean": "rm -rf node_modules/ build/ vendor/ .nyc_output/ coverage/ test/fixtures/output.*",
8282
"test": "semistandard && cpplint && npm run test-unit && npm run test-licensing",
83-
"test-unit": "nyc --reporter=lcov --branches=99 mocha --parallel --slow=1000 --timeout=60000 ./test/unit/*.js",
83+
"test-unit": "nyc --reporter=lcov --branches=99 mocha --slow=1000 --timeout=60000 ./test/unit/*.js",
8484
"test-licensing": "license-checker --production --summary --onlyAllow=\"Apache-2.0;BSD;ISC;MIT\"",
8585
"test-coverage": "./test/coverage/report.sh",
8686
"test-leak": "./test/leak/leak.sh",

‎test/unit/svg.js

+15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
const fs = require('fs');
34
const assert = require('assert');
45

56
const sharp = require('../../');
@@ -99,4 +100,18 @@ describe('SVG input', function () {
99100
fixtures.assertSimilar(fixtures.expected('svg-embedded.png'), data, done);
100101
});
101102
});
103+
104+
it('Converts SVG with truncated embedded PNG', async () => {
105+
const truncatedPng = fs.readFileSync(fixtures.inputPngTruncated).toString('base64');
106+
const svg = `<?xml version="1.0" encoding="UTF-8"?>
107+
<svg width="294" height="240" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
108+
<image width="294" height="240" xlink:href="data:image/png;base64,${truncatedPng}"/>
109+
</svg>`;
110+
111+
const { info } = await sharp(Buffer.from(svg)).toBuffer({ resolveWithObject: true });
112+
assert.strictEqual(info.format, 'png');
113+
assert.strictEqual(info.width, 294);
114+
assert.strictEqual(info.height, 240);
115+
assert.strictEqual(info.channels, 4);
116+
});
102117
});

0 commit comments

Comments
 (0)
Please sign in to comment.