{"record":{"id":"aa25d4aa074971bd","repo":"vercel/next.js","slug":"unknown-syntax-for-viewbox-viewbox","errorCode":null,"errorMessage":"Unknown syntax for viewBox ({viewbox})","messagePattern":"Unknown syntax for viewBox \\((.+?)\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"turbopack/crates/turbopack-image/src/process/svg.rs","lineNumber":56,"sourceCode":"        .unwrap()\n});\n\nfn parse_length(len: &str) -> Result<f64> {\n    let captures = UNIT_REGEX\n        .captures(len)\n        .ok_or_else(|| anyhow!(\"Unknown syntax for length, expected value with unit ({len})\"))?;\n    let val = captures[1].parse::<f64>()?;\n    let unit = &captures[2];\n    let unit_scale = UNITS\n        .get(unit)\n        .ok_or_else(|| anyhow!(\"Unknown unit {unit}\"))?;\n    Ok(val * unit_scale)\n}\n\nfn parse_viewbox(viewbox: &str) -> Result<(f64, f64)> {\n    let captures = VIEW_BOX_CONTENT_REGEX\n        .captures(viewbox)\n        .ok_or_else(|| anyhow!(\"Unknown syntax for viewBox ({viewbox})\"))?;\n    let width = parse_length(&captures[3])?;\n    let height = parse_length(&captures[4])?;\n    Ok((width, height))\n}\n\nfn calculate_by_viewbox(\n    view_box: (f64, f64),\n    width: Option<Result<f64>>,\n    height: Option<Result<f64>>,\n) -> Result<(u32, u32)> {\n    let ratio = view_box.0 / view_box.1;\n    if let Some(width) = width {\n        let width = width?.round() as u32;\n        let height = (width as f64 / ratio).round() as u32;\n        return Ok((width, height));\n    }\n    if let Some(height) = height {\n        let height = height?.round() as u32;","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/vercel/next.js/blob/0ae8c72462952df163f1b1e0726641bc5b40dc93/turbopack/crates/turbopack-image/src/process/svg.rs#L38-L74","documentation":"The viewBox attribute must contain exactly four whitespace-separated numeric tokens (min-x min-y width height) matching VIEW_BOX_CONTENT_REGEX. When the viewBox string doesn't conform (wrong token count, commas instead of spaces, non-numeric tokens), parse_viewbox returns this error. It fires only when width/height attributes are absent and the viewBox fallback is attempted.","triggerScenarios":"An SVG with viewBox=\"0 0 100\" (three values), viewBox=\"0,0,100,100\" (comma-separated), or viewBox containing non-numeric tokens, and no explicit width/height attributes to fall back on.","commonSituations":"SVGs exported by tools that emit comma-separated viewBox values; hand-authored SVGs with a typo in the viewBox; SVGs where width/height were stripped leaving only a malformed viewBox.","solutions":["Format viewBox as four space-separated numbers: viewBox=\"0 0 100 100\".","Add explicit numeric width and height attributes so the viewBox path is not required.","Re-export the SVG from the design tool with standard attribute formatting."],"exampleFix":"<!-- before -->\n<svg viewBox=\"0,0,100,100\">\n\n<!-- after -->\n<svg width=\"100\" height=\"100\" viewBox=\"0 0 100 100\">","handlingStrategy":"validation","validationCode":"// Validate a viewBox string has four space-separated numeric tokens.\nfunction isValidViewBox(vb) {\n  const parts = (vb || '').trim().split(/\\s+/);\n  return parts.length === 4 && parts.every(p => /^[\\w.\\-]+$/.test(p));\n}\n","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always write viewBox with four space-separated numbers (min-x min-y width height).","Provide numeric width/height so the viewBox fallback path is not required.","Lint committed SVGs for viewBox formatting."],"tags":["svg","image-size","viewbox","parsing"],"analyzedSha":"0ae8c72462952df163f1b1e0726641bc5b40dc93","analyzedAt":"2026-08-06T19:44:29.143Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}