Repository navigation
fix(oxvg_optimiser): keep ellipses selected by a stylesheet in convertShapeToPath - #277
Merged
noahbald merged 1 commit intoSep 7, 2026
Conversation
…tShapeToPath convertShapeToPath leaves a shape alone when the document's stylesheet selects it by local name, so the rule still matches after the job runs. The `ellipse` arm tested the wrong flag: in crates/oxvg_optimiser/src/jobs/convert_shape_to_path.rs:184 the guard read `ReferencedShapes::Circle`, which is set by a `circle` selector, instead of `ReferencedShapes::Ellipse`, which line 134 sets for an `ellipse` selector. `ReferencedShapes::Ellipse` was written and never read. With `convertArcs` on, a document whose stylesheet has an `ellipse` rule had its `<ellipse>` rewritten to `<path>`, the rule stopped matching, and the shape lost its styling. In the other direction a `circle` rule blocked ellipse conversion for no reason. The guard now tests `ReferencedShapes::Ellipse`. Two snapshot cases cover both directions.
Owner
|
Thank you |
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
convertShapeToPathleaves a shape alone when the document's stylesheet selects it by local name, so the rule still matches after the job runs. Theellipsearm tested the wrong flag: the guard atcrates/oxvg_optimiser/src/jobs/convert_shape_to_path.rs:184readReferencedShapes::Circle, which acircleselector sets, instead ofReferencedShapes::Ellipse, which line 134 sets for anellipseselector.ReferencedShapes::Ellipsewas written and never read anywhere in the crate.Both directions are reproducible with
convertArcsenabled. A stylesheet containing anellipserule did not protect the ellipse, which was rewritten to<path>, so the rule stopped matching and the shape lost its styling. A stylesheet containing acirclerule and noellipserule blocked ellipse conversion for nothing.The guard now reads
ReferencedShapes::Ellipse. One line, plus two snapshot cases.Motivation and Context
The first case is a silent visual change: the styling in a
<style>block is dropped from the output with no error. The job documents this behaviour under "Differences to SVGO" and it already held forrect,line,polyline,polygonandcircle, soellipsewas the one shape where the guarantee did not hold.There is no open issue for this. I found it reading the job, so the title carries no issue number.
How Has This Been Tested?
macOS 26.2 on aarch64, rustc 1.98.0 stable.
cargo test -p oxvg_optimiser --lockedpasses 58 unit tests and 5 doctests, andcargo test -p oxvg_optimiser --locked --profile release --target=aarch64-apple-darwin, the shape rust.yml uses, passes the same 63.To show the test catches the bug, I reverted only the one-line guard and kept the new cases:
convert_shape_to_path-7then fails with<ellipse cx="10" cy="10" rx="5" ry="4"/>replaced by<path d="M10 6A5 4 0 1 0 10 14 5 4 0 1 0 10 6Z"/>, which is the styling loss described above.cargo clippy -p oxvg_optimiser --profile=test --lockedandcargo doc -p oxvg_optimiser --no-deps --lockedare clean underRUSTFLAGS=-D warningsandRUSTDOCFLAGS=-D warnings, andrustfmt --edition 2024 --checkon the changed file reports no diff.The two snapshots
convert_shape_to_path-7andconvert_shape_to_path-8are new files. No existing snapshot changed.Types of changes
Fixes
convertShapeToPathkeeps an<ellipse>that a stylesheet selects by local name, and converts one when onlycircleis selected.Features
Breaking changes
Checklist: