#820·satori

SVG viewBox containing a tab or line break is parsed as NaN

Author: RaphaelFakhriCreated Sep 29, 2026Updated Sep 29, 2026

Description

parseViewBox in src/utils.ts splits the string with /[, ]/, so only a comma or a single space separates the numbers. The SVG specification also allows tabs and line breaks. Formatted or minified-then-wrapped SVG sources sometimes place a line break inside the attribute.

Reproduction

javascript
import { resolveImageData } from 'satori/src/handler/image'

const svg = '<svg viewBox="0 0\n24 24" xmlns="http://www.w3.org/2000/svg"></svg>'
const [, width, height] = await resolveImageData(
  `data:image/svg+xml;utf8,${encodeURIComponent(svg)}`
)
// width and height are NaN, expected 24 and 24

The same parser is used for the viewBox prop of an inline <svg> element.

Expected behavior

The viewBox is split on any run of whitespace or commas, so the size is 24 by 24.