From 426bde483838a3126de120e3706d0682d70d65be Mon Sep 17 00:00:00 2001 From: Liang Xu Date: Thu, 27 Aug 2026 04:06:51 +0800 Subject: [PATCH] fix(svg): fallback to svg type when metadata parser fails on symbol-based SVGs Fixes #287 Signed-off-by: Liang Xu --- src/ipx.ts | 22 ++++++++++++++++------ test/svg.test.ts | 7 +++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/ipx.ts b/src/ipx.ts index 6d8cc81..1432bc1 100644 --- a/src/ipx.ts +++ b/src/ipx.ts @@ -340,12 +340,22 @@ export function createIPX(userOptions: IPXOptions): IPX { let imageMeta: ImageMeta; try { imageMeta = getImageMeta(sourceData) as ImageMeta; - } catch { - throw new HTTPError({ - statusCode: 400, - statusText: `IPX_INVALID_IMAGE`, - message: `Cannot parse image metadata: ${id}`, - }); + } catch (error) { + const textSample = sourceData.subarray(0, 1024).toString("utf8"); + if (textSample.includes(" { statusText: "IPX_INVALID_SVG", }); }); + + it("processes svg with symbol and use tags without dimensions on root", async () => { + const svgWithSymbol = ``; + const output = await processSVG(svgWithSymbol); + expect(output).toContain(" {