svg/svgo

includesAttrSelector: support different equality checks in attribute selectors too

Open

#2,145 建立於 2025年6月21日

在 GitHub 查看
 (1 留言) (0 反應) (0 負責人)JavaScript (20,308 star) (1,361 fork)batch import
good first issuehelp wanted

描述

We have a helper function named includesAttrSelector. We use this to check if an attribute has been referenced in the stylesheet. If so, the plugin may have different behavior. Usually, by not removing that attribute because it may break styles otherwise.

However, our logic takes a very safe approach, of never deleting attributes if it's been referenced in CSS, even if the operator/check wouldn't match.

For example, suppose an element in an SVG had preserveAspectRatio="xMidYMid meet", with a CSS selector of [preserveAspectRatio^="y"].

This would not match, yet to be on the safe side, we will not remove the attribute. We do not actually check the operator and value, but only the key. Let's improve the logic to actually perform these checks so that we do remove the attribute when it's truly unnecessary.

References:

貢獻者指南