diff --git a/plugins/cleanupIds.js b/plugins/cleanupIds.js
index 55bee0e92..7a30591c8 100644
--- a/plugins/cleanupIds.js
+++ b/plugins/cleanupIds.js
@@ -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(
diff --git a/test/plugins/cleanupIds.26.svg.txt b/test/plugins/cleanupIds.26.svg.txt
new file mode 100644
index 000000000..6a1e23d22
--- /dev/null
+++ b/test/plugins/cleanupIds.26.svg.txt
@@ -0,0 +1,25 @@
+Should handle non-ASCII IDs and resolve not correctly URI encoded references.
+
+See: https://github.com/svg/svgo/issues/1981
+
+===
+
+
+
+@@@
+
+