prefixIds does not apply prefix in non-trivial begin/end expressions of animate tag
Describe the bug
Seems that https://github.com/svg/svgo/issues/848 is fixed only partially, for simple expressions - the fixing commit splits by '; ' and checks for .end presence via endsWith() , and follow-up changes drag that limitation too:
https://github.com/svg/svgo/blame/main/plugins/prefixIds.js#L253
For the following example, being a fragment of animation of rain drops, coming from https://github.com/basmilius/weather-icons (partly-cloudy-day-rain.svg):
<animate id="y1" attributeName="opacity" begin="0s; y1.end+.33s" dur=".67s" keyTimes="0; .25; 1" values="0; 1; 0"/>
the result is:
<animate id="partly-cloudy-day-rain_svg__j" attributeName="opacity" begin="0s; j.end+.33s" dur=".67s" keyTimes="0; .25; 1" values="0; 1; 0"></animate>
To Reproduce Steps to reproduce the behavior:
Expected behavior
<animate id="partly-cloudy-day-rain_svg__j" attributeName="opacity" begin="0s; partly-cloudy-day-rain_svg__j.end+.33s" dur=".67s" keyTimes="0; .25; 1" values="0; 1; 0"></animate>
Desktop (please complete the following information):
- SVGO Version: 3.3.2
- NodeJs Version: 20
- OS: Linux
Also ran into this issue using SVGR. Basic ids and id.end work, but having id.end + 0.06s does not get prefixed and breaks
If anyone interested, I fixed (or at least improved) that in a forked branch https://github.com/alex-kowalczyk/svgo/commits/prefixes-fix/ , namely https://github.com/alex-kowalczyk/svgo/commit/f797003a684b6e125749443dd07f0441f32a1752 (although not enough time & capabilities to prepare full-fledged PR).
@alex-kowalczyk id (the part before “.start” or “.end”) in XML is defined as NameStartChar (NameChar)*, where
NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]
Notably, there are “-” and “.” can be used after the start character and there are character sets beyond [a-zA-Z_]/[\w-].