Skip to content

fix(oxvg_optimiser): keep ellipses selected by a stylesheet in convertShapeToPath - #277

Merged
noahbald merged 1 commit into
noahbald:mainfrom
MaxFreedomPollard:fix/convert-shape-to-path-ellipse-selector
Sep 7, 2026
Merged

noahbald merged 1 commit into
noahbald:mainfrom
MaxFreedomPollard:fix/convert-shape-to-path-ellipse-selector

Conversation

@MaxFreedomPollard

Copy link
Copy Markdown
Contributor

Description

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: the guard at crates/oxvg_optimiser/src/jobs/convert_shape_to_path.rs:184 read ReferencedShapes::Circle, which a circle selector sets, instead of ReferencedShapes::Ellipse, which line 134 sets for an ellipse selector. ReferencedShapes::Ellipse was written and never read anywhere in the crate.

Both directions are reproducible with convertArcs enabled. A stylesheet containing an ellipse rule did not protect the ellipse, which was rewritten to <path>, so the rule stopped matching and the shape lost its styling. A stylesheet containing a circle rule and no ellipse rule 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 for rect, line, polyline, polygon and circle, so ellipse was 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 --locked passes 58 unit tests and 5 doctests, and cargo 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-7 then 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 --locked and cargo doc -p oxvg_optimiser --no-deps --locked are clean under RUSTFLAGS=-D warnings and RUSTDOCFLAGS=-D warnings, and rustfmt --edition 2024 --check on the changed file reports no diff.

The two snapshots convert_shape_to_path-7 and convert_shape_to_path-8 are new files. No existing snapshot changed.

Types of changes

Fixes

  • convertShapeToPath keeps an <ellipse> that a stylesheet selects by local name, and converts one when only circle is selected.

Features

Breaking changes

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

…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.
@noahbald
noahbald merged commit 381e031 into noahbald:main Sep 7, 2026
38 of 40 checks passed
@noahbald

noahbald commented Sep 7, 2026

Copy link
Copy Markdown
Owner

Thank you

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.

2 participants