mirror of
https://github.com/svg/svgo.git
synced 2025-07-29 20:21:14 +03:00
Fix 'cleanupIDs' minify bug due to preserved IDs
Prevent 'cleanupIDs' plugin from producing a preserved ID, including one which matches a preserved prefix, when minifying. Closes #1158
This commit is contained in:
committed by
Lev Solntsev
parent
71c7fe74b9
commit
0e6b0ad8e5
@ -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');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user