diff --git a/lib/parse_stream/svg.js b/lib/parse_stream/svg.js index ccb688c..3d91c4a 100644 --- a/lib/parse_stream/svg.js +++ b/lib/parse_stream/svg.js @@ -11,7 +11,14 @@ var STATE_IGNORE = 2; // we got all the data we want, skip the rest // max size for pre-svg-tag comments plus svg tag itself var MAX_DATA_LENGTH = 65536; -var SVG_HEADER_RE = /]+>/; +// used to get opening tag for top level element in XML, +// skipping comments ('); + + assert.deepStrictEqual( + await probe(Readable.from([ buf ])), + { width: 5, height: 4, type: 'svg', mime: 'image/svg+xml', wUnits: 'px', hUnits: 'px' } + ); + }); + + it('should allow SVG namespace', async function () { + let buf = Buffer.from(''); + + assert.deepStrictEqual( + await probe(Readable.from([ buf ])), + { width: 5, height: 4, type: 'svg', mime: 'image/svg+xml', wUnits: 'px', hUnits: 'px' } + ); + }); + it('should skip BOM', async function () { let size = await probe(Readable.from([ Buffer.from('\ufeff ') ])); @@ -1349,6 +1376,13 @@ describe('File formats', function () { /unrecognized file format/ ); }); + + it('early termination', async function () { + await assert.rejects( + async () => probe(Readable.from([ Buffer.from(''); + + assert.strictEqual(probe.sync(buf), null); + }); + + it('should skip initial comments and directives', async function () { + let buf = Buffer.from(''); + + assert.deepStrictEqual( + probe.sync(buf), + { width: 5, height: 4, type: 'svg', mime: 'image/svg+xml', wUnits: 'px', hUnits: 'px' } + ); + }); + + it('should allow SVG namespace', async function () { + let buf = Buffer.from(''); + + assert.deepStrictEqual( + probe.sync(buf), + { width: 5, height: 4, type: 'svg', mime: 'image/svg+xml', wUnits: 'px', hUnits: 'px' } + ); + }); + it('should skip BOM', async function () { let size = probe.sync(Buffer.from('\ufeff ')); @@ -1457,6 +1515,12 @@ describe('File formats', function () { assert.deepStrictEqual(size, null); }); + + it('early termination', function () { + let size = probe.sync(Buffer.from('