Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cleanupIds): handle uri encoded references #1880

Merged
merged 1 commit into from
Dec 10, 2023

Conversation

SethFalco
Copy link
Member

References to IDs in href or url() references are URIs, and so should be URI encoded/decoded.

We'll have to review and update all usage in SVGO for this, but for now, I've resolved the immediate issue found in Cleanup IDs.

Related

@SethFalco SethFalco merged commit c172c9e into svg:main Dec 10, 2023
10 checks passed
@SethFalco SethFalco deleted the fix/1969 branch December 10, 2023 00:31
nono referenced this pull request in cozy/cozy-stack Dec 11, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [svgo](https://svgo.dev) ([source](https://togithub.com/svg/svgo)) |
[`3.0.5` -> `3.1.0`](https://renovatebot.com/diffs/npm/svgo/3.0.5/3.1.0)
|
[![age](https://developer.mend.io/api/mc/badges/age/npm/svgo/3.1.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/svgo/3.1.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/svgo/3.0.5/3.1.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/svgo/3.0.5/3.1.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>svg/svgo (svgo)</summary>

### [`v3.1.0`](https://togithub.com/svg/svgo/releases/tag/v3.1.0)

[Compare Source](https://togithub.com/svg/svgo/compare/v3.0.5...v3.1.0)

#### What's Changed

##### Bug Fixes

- [**Prefix IDs**](https://svgo.dev/docs/plugins/prefix-ids/), correctly
prefix IDs when `<style>` tag contains XML comments. By
[@&#8203;john-neptune](https://togithub.com/john-neptune) in
[https://github.com/svg/svgo/pull/1736](https://togithub.com/svg/svgo/pull/1736)
- [**Remove Hidden
Elements**](https://svgo.dev/docs/plugins/remove-hidden-elems/), improve
handling of definitions (`<defs>`), namely when `<defs>` are defined at
the end of the document. By
[@&#8203;KTibow](https://togithub.com/KTibow) in
[https://github.com/svg/svgo/pull/1879](https://togithub.com/svg/svgo/pull/1879)
- [**Cleanup Enable
Background**](https://svgo.dev/docs/plugins/cleanup-enable-background/),
clean up inline-styles too. By
[@&#8203;SethFalco](https://togithub.com/SethFalco) in
[https://github.com/svg/svgo/pull/1866](https://togithub.com/svg/svgo/pull/1866)
- [**Cleanup IDs**](https://svgo.dev/docs/plugins/cleanup-ids/), handle
URI encoded references properly. By
[@&#8203;SethFalco](https://togithub.com/SethFalco) in
[https://github.com/svg/svgo/pull/1880](https://togithub.com/svg/svgo/pull/1880)
- [**Inline Styles**](https://svgo.dev/docs/plugins/inline-styles/), no
longer crashes on non-inlined selectors with a pseudo-class. By
[@&#8203;SethFalco](https://togithub.com/SethFalco) in
[https://github.com/svg/svgo/pull/1865](https://togithub.com/svg/svgo/pull/1865)
- Improve handling of URL references in reference attributes
(`url('#a')`) across various plugins. By
[@&#8203;SethFalco](https://togithub.com/SethFalco) in
[https://github.com/svg/svgo/pull/1881](https://togithub.com/svg/svgo/pull/1881)

##### SVG Optimization

- [**Remove Unknowns and
Defaults**](https://svgo.dev/docs/plugins/remove-unknowns-and-defaults/),
now removes defaults in XML declarations too, enabled by default and can
be toggled with `defaultMarkupDeclarations`. By
[@&#8203;SethFalco](https://togithub.com/SethFalco) in
[https://github.com/svg/svgo/pull/1872](https://togithub.com/svg/svgo/pull/1872)

#### Metrics

Before and after using vectors from various sources, with the default
preset of each respective version:

| SVG | Original | v3.0.5 | v3.1.0 | Delta |
|---|---|---|---|---|
| [Arch Linux Logo](https://archlinux.org/art/) | 9.529 KiB | 4.608 KiB
| 4.162 KiB | ⬇️ 0.446 KiB |
|
[Blobs](https://gitlab.gnome.org/GNOME/gnome-backgrounds/-/blob/main/backgrounds/blobs-d.svg)
| 50.45 KiB | 42.949 KiB | 42.949 KiB | |
| [Isometric
Madness](https://inkscape.org/~Denis_Kuznetsky/%E2%98%85isometric-madness)
| 869.034 KiB | 550.153 KiB | 550.153 KiB | |
| [tldr-pages
Banner](https://togithub.com/tldr-pages/tldr/blob/main/images/banner.svg)
| 2.071 KiB | 1.07 KiB | 1.07 KiB | |
| [Wikipedia
Logo](https://en.wikipedia.org/wiki/File:Wikipedia-logo-v2.svg) |
161.551 KiB | 117.146 KiB | 116 KiB | ⬇️ 1.146 KiB |

Before and after of the browser bundle of each respective version:

| | v3.0.5 | v3.1.0 | Delta |
|---|---|---|---|
| svgo.browser.js | 657.5 kB | 660.9 kB | ⬆️ 3.4 kB |

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "before 6am on Monday" in timezone
Europe/Paris, Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/cozy/cozy-stack).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy44Ny4yIiwidXBkYXRlZEluVmVyIjoiMzcuODcuMiIsInRhcmdldEJyYW5jaCI6Im1hc3RlciJ9-->
@ctrlcctrlv
Copy link

Awesome, thanks! 😍

@simonhermann
Copy link

simonhermann commented Feb 21, 2024

Hi @SethFalco
we're using SVGO to optimize svgs only containing a <symbol>. Before 3.1, this worked as expected, with 3.1+, SVGO only returns an empty svg element. I guess it is related to this change.
Is this a bug or am I missing something?

our svgo.config.js

// @ts-check
/** @type {import('svgo').Config} */
module.exports = {
	plugins: [
		{
			name: 'preset-default',
			params: {
				overrides: {
					cleanupIds: false, // prevented removing unused <symbol>s before svgo 3.1
					removeViewBox: false,
				},
			},
		},
		{
			name: 'sortAttrs',
			params: {
				xmlnsOrder: 'alphabetical',
			},
		},
	],
};

@SethFalco
Copy link
Member Author

SethFalco commented Feb 21, 2024

@simonhermann

Hey! Sorry about that. Would you mind sharing an example with me, so I can review it in more detail? If it's private, you're welcome to email it to me instead of uploading it here.

In general, an SVG with only symbols should have always become empty after running through SVGO's default preset, as SVG sprites aren't a use-case the default preset is designed to handle.

I'm not dismissing your issue ofc, we'll get this addressed! Sorry for effectively releasing a breaking change without warning. We'll improve our documentation and handling of SVG sprites for the next minor release.

I'm not sure if it's caused by this PR in your case, but the problem you've raised was ultimately reported in another issue. The author closed it, but it's on my radar, and I'll publish a solution this weekend:

The default behavior will remain the same, but we'll add a preset specific for SVG sprites and add documentation for how to use that preset.

Meanwhile, I recommend you give that issue a read. You're also welcome to chime in if you have any specific thoughts on what should be in or out of an SVG sprite preset. No pressure though!

Let me know if you have any problems.

@simonhermann
Copy link

Hi @SethFalco, thanks for your quick reply!
Nothing to apologize! From your link I see now removeHiddenElems: false makes the difference, I just assumed, setting cleanupIds: false was enough, since it was, before 3.1.

Maybe you could enhance the docs on removeHiddenElems to include an example with <symbol>?
I tried searching the docs, but did not find what I need to do to perserve unused symbols, but of course now I realise they are obviously hidden elements.

Thank you for your support and the awesome work!

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.

[cleanupIDs] symbol is incorrectly removed when its ID is only used by URL-encoded reference
3 participants