From a0c96ea2e57079c156f6b8f2d8d1583d51c23b29 Mon Sep 17 00:00:00 2001 From: ayushsingh82 Date: Fri, 7 Aug 2026 09:44:21 +0530 Subject: [PATCH] fix: fall back to viewBox when SVG logo lacks width/height get_svg_dimensions() only read the width/height XML attributes, so a valid square SVG with only a viewBox (a common export shape from design tools) failed validation with "Could not extract dimensions," contradicting the function's own error message which already claimed viewBox support. Parse viewBox as a fallback when width/height attributes are absent. --- scripts/validate_tokens.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/scripts/validate_tokens.py b/scripts/validate_tokens.py index 67b2b57..4d515da 100644 --- a/scripts/validate_tokens.py +++ b/scripts/validate_tokens.py @@ -351,6 +351,9 @@ def validate_cross_chain_metadata( def get_svg_dimensions(svg_path: Path) -> tuple[int | None, int | None]: """Extract width and height from an SVG file. + Falls back to the viewBox attribute when width/height are absent, since + SVGs exported without explicit pixel dimensions are common and valid. + Args: svg_path: Path to the SVG file. @@ -370,6 +373,14 @@ def get_svg_dimensions(svg_path: Path) -> tuple[int | None, int | None]: height = int(re.sub(r"[^0-9.]", "", height_str).split(".")[0]) return width, height + view_box = root.get("viewBox") + if view_box: + parts = view_box.replace(",", " ").split() + if len(parts) == 4: + width = int(float(parts[2])) + height = int(float(parts[3])) + return width, height + return None, None except Exception: return None, None