@@ -506,44 +506,43 @@ public function minify(array $minify) : void {
506
506
// minify attributes
507
507
if ($ minify ['attributes ' ]) {
508
508
509
+ // cache attributes
510
+ $ min = $ minify ['attributes ' ];
511
+
509
512
// trim attribute
510
- if ($ minify [ ' attributes ' ] ['trim ' ] && $ attributes [$ key ]) {
513
+ if ($ min ['trim ' ] && $ attributes [$ key ]) {
511
514
$ attributes [$ key ] = \trim ($ attributes [$ key ], " \r\n\t" );
512
515
}
513
516
514
517
// boolean attributes
515
- if ($ minify [ ' attributes ' ] ['boolean ' ] && \in_array ($ key , $ attr ['boolean ' ], true )) {
518
+ if ($ min ['boolean ' ] && \in_array ($ key , $ attr ['boolean ' ], true )) {
516
519
$ attributes [$ key ] = null ;
517
520
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
+
518
525
// minify style tag
519
- } elseif ($ key === 'style ' && $ minify [ ' attributes ' ][ ' style ' ] && ! empty ( $ attributes [$ key ]) ) {
526
+ } elseif ($ key === 'style ' && $ min [ ' style ' ] && $ attributes [$ key ]) {
520
527
$ attributes [$ key ] = \trim (\str_replace (
521
- [' ' , ' : ' , ': ' , ' : ' , ' ; ' , ' ; ' , '; ' ],
522
- [' ' , ': ' , ': ' , ': ' , '; ' , '; ' , '; ' ],
528
+ ["\t" , "\r" , "\n" , ' ' , ' : ' , ': ' , ' : ' , ' ; ' , ' ; ' , '; ' ],
529
+ [' ' , '' , ' ' , ' ' , ' : ' , ': ' , ': ' , '; ' , '; ' , '; ' ],
523
530
$ attributes [$ key ]
524
531
), '; ' );
525
532
526
533
// 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 ) {
528
535
$ attributes [$ key ] = \trim (\preg_replace ('/\s+/ ' , ' ' , $ attributes [$ key ]));
529
536
530
537
// minify option tag, always capture the tag to prevent it being removed as a default
531
538
} 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 ]) {
533
540
unset($ attributes [$ key ]);
534
541
}
535
- continue ;
536
542
537
543
// 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 ])) {
545
545
unset($ attributes [$ key ]);
546
- continue ;
547
546
}
548
547
}
549
548
}
0 commit comments