Skip to content

Commit

Permalink
Merge branch 'svg:main' into patch-3
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR committed Apr 26, 2024
2 parents 6ba7bd4 + 89b0c6c commit bc1e613
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
7 changes: 3 additions & 4 deletions plugins/cleanupIds.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,9 @@ export const fn = (_root, params) => {
const value = element.attributes[name];
if (value.includes('#')) {
// replace id in href and url()
element.attributes[name] = value.replace(
`#${encodeURI(id)}`,
`#${currentIdString}`,
);
element.attributes[name] = value
.replace(`#${encodeURI(id)}`, `#${currentIdString}`)
.replace(`#${id}`, `#${currentIdString}`);
} else {
// replace id in begin attribute
element.attributes[name] = value.replace(
Expand Down
25 changes: 25 additions & 0 deletions test/plugins/cleanupIds.26.svg.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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 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 stop-color="#5a2100"/>
</linearGradient>
</defs>
<rect x="30" y="30" height="150" width="370" fill="url(#a)"/>
</svg>

0 comments on commit bc1e613

Please sign in to comment.