fix(cleanupAttrs): handle numeric attribute values (#2219)#2221
Draft
Zhang-Wei-666 wants to merge 2 commits into
Draft
fix(cleanupAttrs): handle numeric attribute values (#2219)#2221Zhang-Wei-666 wants to merge 2 commits into
Zhang-Wei-666 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
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
cleanupAttrsto coerce non-string attribute values to strings before applying newline/trim/space cleanup. - Add a regression test ensuring
cleanupAttrsdoesn’t crash whenwidth/heightare 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.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Collaborator
|
Converting to draft because it's unclear how to reproduce #2219, and artificially making |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2219.
cleanupAttrsassumes attribute values are strings and crashes when an upstream step assigns numeric values such as0towidthorheight.This change coerces non-string attribute values to strings before applying whitespace cleanup and adds a regression test covering numeric
width/heightvalues on<svg>elements without aviewBox.