Improved relocation of script tags
authorAlexander Ebert <ebert@woltlab.com>
Fri, 19 Jul 2013 22:11:47 +0000 (00:11 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 19 Jul 2013 22:11:47 +0000 (00:11 +0200)
Previously, conditional comments weren't properly moved, resulting in IE-specific JavaScript being executed in all browsers.

wcfsetup/install/files/lib/util/HeaderUtil.class.php

index 1694969680b3c8b8b807965d143222f320f1634c..6733575fb8d6257197d4b8cab0bd461523f99886 100644 (file)
@@ -90,8 +90,13 @@ final class HeaderUtil {
                
                // move script tags to the bottom of the page
                $javascript = array();
-               self::$output = preg_replace_callback('~<script(.*?)</script>~s', function($matches) use (&$javascript) {
-                       $javascript[] = $matches[0];
+               self::$output = preg_replace_callback('~(?P<conditionBefore><!--\[IF [^<]+\s*)?<script(?P<script>.*?)</script>(?P<conditionAfter>\s*<!\[ENDIF]-->)?~s', function($matches) use (&$javascript) {
+                       $match = '';
+                       if (isset($matches['conditionBefore'])) $match .= $matches['conditionBefore'];
+                       $match .= '<script' . $matches['script'] . '</script>';
+                       if (isset($matches['conditionAfter'])) $match .= $matches['conditionAfter'];
+                       
+                       $javascript[] = $match;
                        return '';
                }, self::$output);