@@ -506,44 +506,43 @@ public function minify(array $minify) : void {
506506 // minify attributes
507507 if ($ minify ['attributes ' ]) {
508508
509+ // cache attributes
510+ $ min = $ minify ['attributes ' ];
511+
509512 // trim attribute
510- if ($ minify [ ' attributes ' ] ['trim ' ] && $ attributes [$ key ]) {
513+ if ($ min ['trim ' ] && $ attributes [$ key ]) {
511514 $ attributes [$ key ] = \trim ($ attributes [$ key ], " \r\n\t" );
512515 }
513516
514517 // boolean attributes
515- if ($ minify [ ' attributes ' ] ['boolean ' ] && \in_array ($ key , $ attr ['boolean ' ], true )) {
518+ if ($ min ['boolean ' ] && \in_array ($ key , $ attr ['boolean ' ], true )) {
516519 $ attributes [$ key ] = null ;
517520
521+ // remove empty attributes
522+ } elseif (\in_array ($ attributes [$ key ], ['' , null ], true ) && $ min ['empty ' ] && \in_array ($ key , $ attr ['empty ' ], true )) {
523+ unset($ attributes [$ key ]);
524+
518525 // minify style tag
519- } elseif ($ key === 'style ' && $ minify [ ' attributes ' ][ ' style ' ]) {
526+ } elseif ($ key === 'style ' && $ min [ ' style ' ] && $ attributes [ $ key ]) {
520527 $ attributes [$ key ] = \trim (\str_replace (
521- [' ' , ' : ' , ': ' , ' : ' , ' ; ' , ' ; ' , '; ' ],
522- [' ' , ': ' , ': ' , ': ' , '; ' , '; ' , '; ' ],
528+ ["\t" , "\r" , "\n" , ' ' , ' : ' , ': ' , ' : ' , ' ; ' , ' ; ' , '; ' ],
529+ [' ' , '' , ' ' , ' ' , ' : ' , ': ' , ': ' , '; ' , '; ' , '; ' ],
523530 $ attributes [$ key ]
524531 ), '; ' );
525532
526533 // trim classes
527- } elseif ($ key === 'class ' && $ minify [ ' attributes ' ][ ' class ' ] && \mb_strpos ($ attributes [$ key ], ' ' ) !== false ) {
534+ } elseif ($ key === 'class ' && $ min [ ' class ' ] && \mb_strpos ($ attributes [$ key ] ?? '' , ' ' ) !== false ) {
528535 $ attributes [$ key ] = \trim (\preg_replace ('/\s+/ ' , ' ' , $ attributes [$ key ]));
529536
530537 // minify option tag, always capture the tag to prevent it being removed as a default
531538 } elseif ($ key === 'value ' && $ tag === 'option ' ) {
532- if ($ minify [ ' attributes ' ] ['option ' ] && isset ($ this ->children [0 ]) && $ this ->children [0 ]->text () === $ attributes [$ key ]) {
539+ if ($ min ['option ' ] && isset ($ this ->children [0 ]) && $ this ->children [0 ]->text () === $ attributes [$ key ]) {
533540 unset($ attributes [$ key ]);
534541 }
535- continue ;
536542
537543 // remove tag specific default attribute
538- } elseif ($ minify ['attributes ' ]['default ' ] && isset ($ attr ['default ' ][$ tag ][$ key ]) && ($ attr ['default ' ][$ tag ][$ key ] === true || $ attr ['default ' ][$ tag ][$ key ] === $ attributes [$ key ])) {
539- unset($ attributes [$ key ]);
540- continue ;
541- }
542-
543- // remove other attributes
544- if ($ attributes [$ key ] === '' && $ minify ['attributes ' ]['empty ' ] && \in_array ($ key , $ attr ['empty ' ], true )) {
544+ } elseif ($ min ['default ' ] && isset ($ attr ['default ' ][$ tag ][$ key ]) && ($ attr ['default ' ][$ tag ][$ key ] === true || $ attr ['default ' ][$ tag ][$ key ] === $ attributes [$ key ])) {
545545 unset($ attributes [$ key ]);
546- continue ;
547546 }
548547 }
549548 }
0 commit comments