Fix SVG handling for width and height attributes#19027
Open
chris78er wants to merge 1 commit into
Open
Conversation
### Description
Transforming an SVG with percentage root dimensions (`width="100%" height="100%"` + `viewBox`) produces duplicate `width`/`height` attributes → invalid XML ("Attribute width redefined"), so the image won't render.
Regression from **5.9.15** (commit `0a643d71`), which changed the `loadImage()` condition in `src/image/Svg.php` to `!width && !height`.
### Cause
In `src/image/Svg.php`, `SVG_WIDTH_RE`/`SVG_HEIGHT_RE` only match px, so `width="100%"` counts as *missing*. `loadImage()` then prepends `width="…px"` while the original `100%` stays → two attributes. `resize()`'s percentage-cleanup sits in the branch that's no longer reached.
### Fix
In `src/image/Svg.php`, strip percentage dimensions in `loadImage()` before prepending, reusing the existing constants.
Member
|
Can you provide an SVG file that could be used to reproduce this issue? |
Author
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.


Description
Transforming an SVG with percentage root dimensions (
width="100%" height="100%"+viewBox) produces duplicatewidth/heightattributes → invalid XML ("Attribute width redefined"), so the image won't render.Regression from 5.9.15 (commit
0a643d71), which changed theloadImage()condition insrc/image/Svg.phpto!width && !height.Cause
In
src/image/Svg.php,SVG_WIDTH_RE/SVG_HEIGHT_REonly match px, sowidth="100%"counts as missing.loadImage()then prependswidth="…px"while the original100%stays → two attributes.resize()'s percentage-cleanup sits in the branch that's no longer reached.Fix
In
src/image/Svg.php, strip percentage dimensions inloadImage()before prepending, reusing the existing constants.