| @@ -454,10 +454,27 @@ | ||
| 454 | 454 | // and says the same thing: this sheet is parked under `print` and |
| 455 | 455 | // becomes something else on load. Any plugin using the standard |
| 456 | 456 | // print/swap idiom is read correctly rather than merged into a |
| 457 | 457 | // print-only bundle and stripped of its handler (#335 review, issue 3). |
| 458 | - if ( preg_match( '#\bonload\s*=\s*(["\'])\s*this\.media\s*=\s*(["\'])([^"\']*)\2#i', $tag, $m ) ) { | |
| 459 | - return $m[3]; | |
| 458 | + // | |
| 459 | + // The assignment can sit anywhere in the handler. loadCSS spells it | |
| 460 | + // `this.onload=null;this.media='all'`, and matching only a handler | |
| 461 | + // that STARTS with `this.media` filed two such sheets as real print | |
| 462 | + // sheets: merged into a `media="print"` bundle with no onload, they | |
| 463 | + // never applied on screen. (#560) | |
| 464 | + // | |
| 465 | + // The attribute is decoded first: a tag built with esc_attr() carries | |
| 466 | + // `this.media='all'`. An assignment whose value is not a | |
| 467 | + // literal (`this.media=this.dataset.media`) is still a swap; it | |
| 468 | + // restores to the screen, so it is read as `all`. | |
| 469 | + if ( preg_match( '#(?<![-\w])onload\s*=\s*(?:"([^"]*)"|\'([^\']*)\')#i', $tag, $h ) ) { | |
| 470 | + $handler = html_entity_decode( '' !== $h[1] ? $h[1] : ( $h[2] ?? '' ), ENT_QUOTES | ENT_HTML5, 'UTF-8' ); | |
| 471 | + if ( preg_match( '#\bthis\.media\s*=\s*(["\'])([^"\']*)\1#i', $handler, $m ) ) { | |
| 472 | + return $m[2]; | |
| 473 | + } | |
| 474 | + if ( preg_match( '#\bthis\.media\s*=(?!=)#i', $handler ) ) { | |
| 475 | + return 'all'; | |
| 476 | + } | |
| 460 | 477 | } |
| 461 | 478 | |
| 462 | 479 | return ''; |
| 463 | 480 | } |