Repository navigation
fix(small-images): only read the width/height CSS properties (#531) - #536
Open
samiarif02 wants to merge 1 commit into
Open
samiarif02 wants to merge 1 commit into
samiarif02 wants to merge 1 commit into
Conversation
The small-image filter read inline dimensions with /width\s*:\s*(\d+)/ and /height\s*:\s*(\d+)/. Those also match inside stroke-width, border-width and line-height, so an SVG with style="stroke-width:1px" or an image with style="border-width:1px;width:600px" was read as 1px wide and removed as a small image. Anchor each pattern to a property boundary (start of the style string or after a ;) so only the width/height properties match. Fixes kepano#531
This branch has not been deployed
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.
Problem
The small-image filter reads an element's inline dimensions with:
Because
widthandheightare matched anywhere in the style string, they also match inside other properties:stroke-width:1px→ width read as1border-width: 1px; width: 600px→ width read as1(first match wins)line-height: 1.5→ height read as1So an SVG with
style="stroke-width:1px"whose real size comes from itsviewBox, or a large image with aborder-width, is treated as 1px wide and dropped byfindSmallImages/removeSmallImages. Reported in #531.Fix
Anchor each pattern to a CSS property boundary — the start of the style string or just after a
;(ignoring surrounding whitespace) — so only thewidth/heightproperties match, notstroke-width,border-widthorline-height:Tests
Added
tests/small-image-style-width.test.tswith two cases (an SVG sized only byviewBoxplusstroke-width:1px, and an image withborder-width:1px;width:600px). Both fail onmain(the elements are removed) and pass with the fix. Fullvitest runis green except the pre-existingwebsite/*suites that need the@lezer/*packages, which fail the same way onmain.