- Timestamp:
- 02/07/2024 05:58:19 AM (23 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/trac.wordpress.org/templates/update-headers.php
r12855 r13181 7 7 function domdocument_from_url( $url ) { 8 8 $html = file_get_contents( $url ); 9 10 /* 11 * Escape HTML within Javascript strings. 12 * DomDocument doesn't handle HTML tags within Javascript strings. 13 * See https://stackoverflow.com/questions/40703313/php-domdocument-errors-while-parsing-unescaped-strings 14 */ 15 $html = preg_replace_callback( 16 '!<script([^>]+)>(.*?)</script>!ism', 17 function( $m ) { 18 $escaped = $m[2]; 19 $escaped = str_replace( array( '<', '>' ), array( '\x3C', '\x3E' ), $escaped ); 20 return "<script{$m[1]}>{$escaped}</script>"; 21 }, 22 $html 23 ); 9 24 10 25 $doc = new DOMDocument(); … … 42 57 $html = preg_replace( '#<style([^>]*)><!\[CDATA\[(.+?)\]\]></style>#ism', "<style$1>$2</style>", $html ); 43 58 44 // Escape CDATA tags in <script>45 $html = preg_replace( '#<script([^>]*)><!\[CDATA\[(.+?)\]\]></script>#ism', "<script$1> //<![CDATA[\n$2\n//]]></script>", $html );59 // Remove CDATA tags in <script> 60 $html = preg_replace( '#<script([^>]*)><!\[CDATA\[(.+?)\]\]></script>#ism', "<script$1>$2</script>", $html ); 46 61 47 62 // Remove trailing whitespace.
Note: See TracChangeset
for help on using the changeset viewer.