diff --git a/plugins/cleanupIDs.js b/plugins/cleanupIDs.js
index f1fdc9f3..918474a0 100644
--- a/plugins/cleanupIDs.js
+++ b/plugins/cleanupIDs.js
@@ -121,13 +121,18 @@ exports.fn = function(data, params) {
return data;
}
+ const idPreserved = id => preserveIDs.has(id) || idMatchesPrefix(preserveIDPrefixes, id);
+
for (var ref of referencesIDs) {
var key = ref[0];
if (IDs.has(key)) {
// replace referenced IDs with the minified ones
- if (params.minify && !preserveIDs.has(key) && !idMatchesPrefix(preserveIDPrefixes, key)) {
- currentIDstring = getIDstring(currentID = generateID(currentID), params);
+ if (params.minify && !idPreserved(key)) {
+ do {
+ currentIDstring = getIDstring(currentID = generateID(currentID), params);
+ } while (idPreserved(currentIDstring));
+
IDs.get(key).attr('id').value = currentIDstring;
for (var attr of ref[1]) {
@@ -143,7 +148,7 @@ exports.fn = function(data, params) {
// remove non-referenced IDs attributes from elements
if (params.remove) {
for(var keyElem of IDs) {
- if (!preserveIDs.has(keyElem[0]) && !idMatchesPrefix(preserveIDPrefixes, keyElem[0])) {
+ if (!idPreserved(keyElem[0])) {
keyElem[1].removeAttr('id');
}
}
diff --git a/test/plugins/cleanupIDs.16.svg b/test/plugins/cleanupIDs.16.svg
new file mode 100644
index 00000000..dc20966f
--- /dev/null
+++ b/test/plugins/cleanupIDs.16.svg
@@ -0,0 +1,23 @@
+
+
+@@@
+
+
+
+@@@
+
+{"preserve": "a"}
diff --git a/test/plugins/cleanupIDs.17.svg b/test/plugins/cleanupIDs.17.svg
new file mode 100644
index 00000000..93ad9bc4
--- /dev/null
+++ b/test/plugins/cleanupIDs.17.svg
@@ -0,0 +1,23 @@
+
+
+@@@
+
+
+
+@@@
+
+{"preservePrefixes": "a"}
diff --git a/test/plugins/cleanupIDs.18.svg b/test/plugins/cleanupIDs.18.svg
new file mode 100644
index 00000000..bba201ff
--- /dev/null
+++ b/test/plugins/cleanupIDs.18.svg
@@ -0,0 +1,23 @@
+
+
+@@@
+
+
+
+@@@
+
+{"preservePrefixes": "a"}