Skip to content

fix: use svg pass-thru when requested format is svg - #262

Merged
pi0 merged 6 commits into
unjs:mainfrom
sgarner:fix/svg-output-format
Jul 26, 2026
Merged

fix: use svg pass-thru when requested format is svg#262
pi0 merged 6 commits into
unjs:mainfrom
sgarner:fix/svg-output-format

Conversation

@sgarner

@sgarner sgarner commented Apr 8, 2025

Copy link
Copy Markdown
Contributor

Resolves #261

Summary by CodeRabbit

  • Bug Fixes
    • Improved SVG handling in image processing: SVGs now pass through when no output format is specified or when SVG is explicitly requested.
    • SVG inputs are rasterized when a non-SVG format (e.g., WebP) is requested; SVG format requests for non-SVG inputs are ignored.
    • When SVGO is enabled, generated SVGs are sanitized to remove unsafe content such as scripts and inline event handlers.
  • Tests
    • Added SVG-focused test coverage for pass-through, format selection, rasterization, and SVGO sanitization.

@pi0
pi0 self-requested a review as a code owner July 23, 2025 11:38
@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: f7e13915-c8ab-4f8a-b55d-910f8ea99071

📥 Commits

Reviewing files that changed from the base of the PR and between bad635b and e80a478.

📒 Files selected for processing (1)
  • test/index.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/index.test.ts

📝 Walkthrough

Walkthrough

The ipx() flow now preserves SVG output for SVG sources when no format or svg is requested, while non-SVG requests continue through rasterization. Tests cover format aliases, fallback behavior, and SVGO sanitization.

Changes

SVG format resolution

Layer / File(s) Summary
Resolve and validate SVG output format
src/ipx.ts, test/index.test.ts
SVG sources are passed through or optimized for SVG output, other formats retain JPEG fallback behavior, and tests cover format requests, rasterization, non-SVG inputs, and script removal.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: SVG pass-through when SVG is explicitly requested.
Linked Issues check ✅ Passed The change matches #261 by returning SVG for SVG sources when svg is requested, while preserving optional SVGO optimization.
Out of Scope Changes check ✅ Passed The added behavior and tests stay focused on SVG pass-through and SVGO handling, with no clear unrelated scope creep.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

pi0 and others added 4 commits July 26, 2026 20:58
Guards the fix for unjs#261: requesting `f=svg`/`format=svg` on an SVG source
must pass through instead of falling back to jpeg. Both cases fail without
the fix. Also pins the surrounding behavior that is easy to regress in the
format ternary: implicit pass-thru, rasterizing to another format, `f=svg`
on a non-SVG source, and svgo script removal.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The svg branch always returns early, so it does not need to be threaded
through `format`. Lifting the check above the ternary keeps the original
two-level shape instead of three, and avoids implying that "svg" is a
value sharp could ever receive in `toFormat()`.

No behavior change.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@codecov

codecov Bot commented Jul 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.18%. Comparing base (70acd53) to head (e80a478).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #262      +/-   ##
==========================================
+ Coverage   75.00%   77.18%   +2.18%     
==========================================
  Files           8        8              
  Lines         412      412              
  Branches      109      109              
==========================================
+ Hits          309      318       +9     
+ Misses         85       77       -8     
+ Partials       18       17       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pi0
pi0 merged commit 28def87 into unjs:main Jul 26, 2026
6 checks passed
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.

Cannot request svg output format for svg source files

2 participants