Skip to content

fix(cleanupAttrs): handle numeric attribute values (#2219)#2221

Draft
Zhang-Wei-666 wants to merge 2 commits into
svg:mainfrom
Zhang-Wei-666:main
Draft

fix(cleanupAttrs): handle numeric attribute values (#2219)#2221
Zhang-Wei-666 wants to merge 2 commits into
svg:mainfrom
Zhang-Wei-666:main

Conversation

@Zhang-Wei-666

Copy link
Copy Markdown

Fixes #2219.

cleanupAttrs assumes attribute values are strings and crashes when an upstream step assigns numeric values such as 0 to width or height.

This change coerces non-string attribute values to strings before applying whitespace cleanup and adds a regression test covering numeric width / height values on <svg> elements without a viewBox.

Copilot AI review requested due to automatic review settings May 9, 2026 09:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a crash in the cleanupAttrs plugin when upstream plugins assign non-string attribute values (e.g., numeric width/height), addressing issue #2219 and adding a regression test to cover the scenario.

Changes:

  • Update cleanupAttrs to coerce non-string attribute values to strings before applying newline/trim/space cleanup.
  • Add a regression test ensuring cleanupAttrs doesn’t crash when width/height are numeric.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
plugins/cleanupAttrs.js Coerces attribute values to strings before running whitespace cleanup logic.
lib/svgo.test.js Adds a regression test for numeric width/height values passed through cleanupAttrs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread plugins/cleanupAttrs.js Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@KTibow

KTibow commented May 24, 2026

Copy link
Copy Markdown
Collaborator

Converting to draft because it's unclear how to reproduce #2219, and artificially making node.attributes.width = 0 is the wrong kind of reproduction to use in a test.

@KTibow KTibow marked this pull request as draft May 24, 2026 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SVGO crashes on a file where the <svg> element is missing both width/height and viewBox attributes

3 participants