@@ -153,13 +153,21 @@ static void adjustSVGAttributes(Attributes attrs) {
153153 if (attrs == null || attrs .isEmpty ()) {
154154 return ;
155155 }
156-
157- for (String lowerCaseAttr : new ArrayList <>(attrs .keySet ())) {
158- if (SVG_ATTRIBUTES .containsKey (lowerCaseAttr )) {
156+ ArrayList <String > toAdjust = null ;
157+ for (AttributeNode attr : attrs ) {
158+ if (SVG_ATTRIBUTES .containsKey (attr .name )) {
159+ if (toAdjust == null ) {
160+ toAdjust = new ArrayList <>(4 );
161+ }
162+ toAdjust .add (attr .name );
163+ }
164+ }
165+ if (toAdjust != null ) {
166+ for (String lowerCaseAttr : toAdjust ) {
159167 AttributeNode attr = attrs .get (lowerCaseAttr );
168+ attrs .remove (lowerCaseAttr );
160169 attr .name = SVG_ATTRIBUTES .get (lowerCaseAttr );
161170 attrs .put (attr );
162- attrs .remove (lowerCaseAttr );
163171 }
164172 }
165173 }
@@ -185,15 +193,25 @@ static void adjustForeignAttributes(Attributes attrs) {
185193 return ;
186194 }
187195
188- for (String lowerCaseAttr : new ArrayList <>(attrs .keySet ())) {
189- if (FOREIGN_ATTRIBUTES_TO_ADJUST .containsKey (lowerCaseAttr )) {
196+ ArrayList <String > toAdjust = null ;
197+ for (AttributeNode attr : attrs ) {
198+ if (FOREIGN_ATTRIBUTES_TO_ADJUST .containsKey (attr .name )) {
199+ if (toAdjust == null ) {
200+ toAdjust = new ArrayList <>(4 );
201+ }
202+ toAdjust .add (attr .name );
203+ }
204+ }
205+
206+ if (toAdjust != null ) {
207+ for (String lowerCaseAttr : toAdjust ) {
190208 String [] adj = FOREIGN_ATTRIBUTES_TO_ADJUST .get (lowerCaseAttr );
191209 AttributeNode attr = attrs .get (lowerCaseAttr );
210+ attrs .remove (lowerCaseAttr );
192211 attr .prefix = adj [0 ];
193212 attr .name = adj [1 ];
194213 attr .namespace = adj [2 ];
195214 attrs .put (attr );
196- attrs .remove (lowerCaseAttr );
197215 }
198216 }
199217 }
0 commit comments