@@ -136,8 +136,8 @@ public function parse(tokenise $tokens) : void {
136
136
case 'attributevalue ' :
137
137
if ($ attr ) {
138
138
$ value = \trim ($ token ['value ' ], "= \t\r\n" );
139
- if (($ pos = \strpos ($ value , '" ' )) === 0 || \strpos ($ value , "' " ) === 0 ) {
140
- $ value = \trim ($ value , $ pos === 0 ? '" ' : "' " );
139
+ if (($ double = \str_starts_with ($ value , '" ' )) === true || \str_starts_with ($ value , "' " )) {
140
+ $ value = \trim ($ value , $ double ? '" ' : "' " );
141
141
}
142
142
$ attributes [$ attr ] = \html_entity_decode ($ value , ENT_QUOTES | ENT_HTML5 );
143
143
$ attr = null ;
@@ -416,6 +416,7 @@ public function minify(array $minify) : void {
416
416
// minify attributes
417
417
$ tag = $ this ->tagName ;
418
418
$ attributes = $ this ->attributes ;
419
+ $ skipurl = isset ($ attr ['urlskip ' ][$ tag ]) && !$ this ->hasAttribute ($ attributes , $ attr ['urlskip ' ][$ tag ]);
419
420
$ host = null ;
420
421
foreach ($ attributes AS $ key => $ value ) {
421
422
@@ -427,7 +428,7 @@ public function minify(array $minify) : void {
427
428
}
428
429
429
430
// minify url attributes when not in list or match attribute
430
- if ($ minify ['urls ' ] && $ attributes [ $ key ] && \in_array ($ key , $ attr ['urls ' ], true ) && (! \in_array ( $ tag , \array_keys ( $ attr [ ' urlskip ' ]), true ) || $ this -> hasAttribute ( $ attributes , $ attr [ ' urlskip ' ][ $ tag ])) ) {
431
+ if ($ minify ['urls ' ] && $ value && \in_array ($ key , $ attr ['urls ' ], true ) && ! $ skipurl ) {
431
432
432
433
// make folder variables
433
434
if ($ folder === null && isset ($ _SERVER ['HTTP_HOST ' ], $ _SERVER ['REQUEST_URI ' ])) {
@@ -440,7 +441,7 @@ public function minify(array $minify) : void {
440
441
}
441
442
442
443
// strip scheme from absolute URL's if the same as current scheme
443
- if ($ minify ['urls ' ]['scheme ' ] && \mb_strpos ($ attributes [$ key ], $ scheme ) === 0 ) {
444
+ if ($ minify ['urls ' ]['scheme ' ] && \str_starts_with ($ attributes [$ key ], $ scheme )) {
444
445
$ attributes [$ key ] = \mb_substr ($ attributes [$ key ], \mb_strlen ($ scheme )-2 );
445
446
}
446
447
@@ -469,7 +470,7 @@ public function minify(array $minify) : void {
469
470
if ($ minify ['urls ' ]['relative ' ] && $ folder ) {
470
471
471
472
// minify
472
- if (\mb_strpos ($ attributes [$ key ], $ folder ) === 0 && ($ folder !== '/ ' || \mb_strpos ($ attributes [$ key ], '// ' ) !== 0 )) {
473
+ if (\str_starts_with ($ attributes [$ key ], $ folder ) && ($ folder !== '/ ' || ! \str_starts_with ($ attributes [$ key ], '// ' ))) {
473
474
if ($ attributes [$ key ] === $ folder && $ attributes [$ key ] !== $ _SERVER ['REQUEST_URI ' ]) {
474
475
$ attributes [$ key ] = './ ' ;
475
476
} else {
@@ -479,7 +480,7 @@ public function minify(array $minify) : void {
479
480
}
480
481
481
482
// use parent folders if it is shorter
482
- if ($ minify ['urls ' ]['parent ' ] && $ dirs && \mb_strpos ($ attributes [$ key ], '/ ' ) === 0 && !\str_contains ($ attributes [$ key ], '// ' )) {
483
+ if ($ minify ['urls ' ]['parent ' ] && $ dirs && \str_starts_with ($ attributes [$ key ], '/ ' ) && !\str_contains ($ attributes [$ key ], '// ' )) {
483
484
$ isDir = \mb_strrpos ($ attributes [$ key ], '/ ' ) === \mb_strlen ($ attributes [$ key ])-1 ;
484
485
$ compare = \explode ('/ ' , \trim ($ isDir ? $ attributes [$ key ] : \dirname ($ attributes [$ key ]), '/ ' ));
485
486
$ update = false ;
@@ -617,7 +618,8 @@ public function minify(array $minify) : void {
617
618
618
619
protected function hasAttribute (array $ attr , array $ items ) {
619
620
foreach ($ items AS $ key => $ item ) {
620
- if (!isset ($ attr [$ key ]) || !\in_array ($ attr [$ key ], $ item , true )) {
621
+ $ lower = \mb_strtolower ($ key );
622
+ if (!isset ($ attr [$ lower ]) || !\in_array ($ attr [$ lower ], $ item , true )) {
621
623
return false ;
622
624
}
623
625
}
@@ -755,7 +757,7 @@ public function find(array $selector, bool $searchChildren = true) : array {
755
757
// match subcode
756
758
case '|= ' :
757
759
if ($ item ['sensitive ' ]) {
758
- if ($ current !== $ item ['value ' ] && \mb_strpos ($ current , $ item ['value ' ].'- ' ) !== 0 ) {
760
+ if ($ current !== $ item ['value ' ] && ! \str_starts_with ($ current , $ item ['value ' ].'- ' )) {
759
761
$ match = false ;
760
762
break ;
761
763
}
0 commit comments