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 no-uri-encoded references #1982

Merged
merged 3 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugins/cleanupIds.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ export const fn = (_root, params) => {
if (value.includes('#')) {
// replace id in href and url()
element.attributes[name] = value.replace(
`#${encodeURI(id)}`,
new RegExp(`#(${id}|${encodeURI(id)})`),
`#${currentIdString}`,
);
liuweifeng marked this conversation as resolved.
Show resolved Hide resolved
} else {
Expand Down
29 changes: 29 additions & 0 deletions test/plugins/cleanupIds.26.svg.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Should handle non-ASCII IDs and resolve not correctly URI encoded references.

See: https://github.com/svg/svgo/issues/1981

===

<svg xmlns="http://www.w3.org/2000/svg">
<defs>
<linearGradient id="渐变_1" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="10%" stop-color="#c71700" />
<stop offset="60%" stop-color="orange" />
<stop offset="100%" stop-color="#5a2100" />
</linearGradient>
</defs>
<rect x="30" y="30" height="150" width="370" fill="url(#渐变_1)" />
</svg>

@@@

<svg xmlns="http://www.w3.org/2000/svg">
<defs>
<linearGradient id="a" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="10%" stop-color="#c71700"/>
<stop offset="60%" stop-color="orange"/>
liuweifeng marked this conversation as resolved.
Show resolved Hide resolved
<stop offset="100%" stop-color="#5a2100"/>
</linearGradient>
</defs>
<rect x="30" y="30" height="150" width="370" fill="url(#a)"/>
</svg>