Changeset 2001833
- Timestamp:
- 12/26/2018 06:25:17 PM (7 years ago)
- Location:
- html-minifier/trunk
- Files:
-
- 3 edited
-
html-minifier.php (modified) (2 diffs)
-
inc/src/HTMLMinifier.php (modified) (6 diffs)
-
readme.md (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
html-minifier/trunk/html-minifier.php
r1995957 r2001833 7 7 Plugin URI: http://www.terresquall.com/web/html-minifier/ 8 8 Description: Provides a variety of optimisation options (e.g. minification, caching, code reorganisation) for your site's source code to help meet today's web performance standards. 9 Version: 2.3. 210 Dated: 07/12/20189 Version: 2.3.3 10 Dated: 27/12/2018 11 11 Author: Terresquall 12 12 Author URI: http://www.terresquall.com/ … … 29 29 require_once HTML_MINIFIER__PLUGIN_DIR . 'inc/HTMLMinifier.manager.php'; 30 30 31 define('HTML_MINIFIER_PLUGIN_VERSION', '2.3. 2');32 define('HTML_MINIFIER_PLUGIN_VERSION_DATE', ' 17 December 2018');31 define('HTML_MINIFIER_PLUGIN_VERSION', '2.3.3'); 32 define('HTML_MINIFIER_PLUGIN_VERSION_DATE', '27 December 2018'); 33 33 34 34 add_action('init',array('HTMLMinifier_Manager','init')); -
html-minifier/trunk/inc/src/HTMLMinifier.php
r1995957 r2001833 9 9 @author Terence Pek <terence@terresquall.com> 10 10 @website www.terresquall.com 11 @version 3.2.2 12 @dated 17/12/2018 13 @notes - Fixed a critical error with the remove comments functionality in Javascript and CSS that caused some major bugs. 11 @version 3.2.3 12 @dated 27/12/2018 13 @notes - Fixed another critical error with the remove comments functionality that caused some major bugs. 14 - Fixed a critical error with the remove comments functionality in Javascript and CSS that caused some major bugs. 14 15 - Rewrote the remove_comments() function in HTML minifier to make it more efficient. The old function incorrectly identified regexes and strings previously, and was not efficient. 15 16 - Fixed a bug that caused 'shift_script_tags_to_bottom' to always create script tags at the end of the page. … … 38 39 public static $CacheExpiry = 86400; // Time in seconds. 86400 is 1 day. 39 40 40 const VERSION = '3.2. 2';41 const VERSION = '3.2.3'; 41 42 const SIGNATURE = 'Original size: %d bytes, minified: %d bytes. HTMLMinifier: www.terresquall.com/web/html-minifier.'; 42 43 const CACHE_SIG = 'Server cached on %s.'; … … 1060 1061 1061 1062 // Encapsulated content that we want to capture (in regex without delimiters). 1062 $encap_start = array("'",'"'); 1063 $encap_end = array("(?:(?<!\\\\)|(?<=^|[^\\\\])(\\\\{2})+)'","(?:(?<!\\\\)|(?<=^|[^\\\\])(\\\\{2})+)\""); 1063 $encap_start = array( 1064 's_quote' => "'", 1065 'd_quote' => '"' 1066 ); 1067 $encap_end = array( 1068 's_quote' => "(?:(?<!\\\\)|(?<=^|[^\\\\])(\\\\{2})+)'", 1069 'd_quote' => "(?:(?<!\\\\)|(?<=^|[^\\\\])(\\\\{2})+)\"" 1070 ); 1071 1064 1072 if($type === 'css') { 1065 $encap_start[ ] = '(?:url|image)\\(';1066 $encap_end[ ] = '\\)';1073 $encap_start['url_func'] = '(?:url|image)\\('; 1074 $encap_end['url_func'] = '\\)'; 1067 1075 } else { 1068 $encap_start[ ] = '(?<=^|[[{};:=?(,*]|&&|\\|\\|)\s*/(?![/\\*])';1069 $encap_end[ ] = '(?:(?<!\\\\)|(?<=^|[^\\\\])(\\\\{2})+)/[gim]?';1076 $encap_start['regex'] = '(?<=^|[[{};:=?(,*!]|&&|\\|\\||return)\s*/(?![/\\*])'; 1077 $encap_end['regex'] = '(?:(?<!\\\\)|(?<=^|[^\\\\])(\\\\{2})+)/[gim]?'; 1070 1078 } 1071 1079 1072 1080 // Comments that we want to capture. 1073 $comments_start = array('//','/\\*'); 1074 $comments_end = array('(?:\\R|$)','\\*/'); 1081 $comments_start = array( 1082 's_comment' => '//', 1083 'm_comment' => '/\\*' 1084 ); 1085 $comments_end = array( 1086 's_comment' => '(?:\\R|$)', 1087 'm_comment' => '\\*/' 1088 ); 1075 1089 1076 1090 // Concatenate both arrays. … … 1087 1101 1088 1102 // Find the item that has triggered encapsulation. 1089 $idx = -1;1103 $idx = false; 1090 1104 foreach($total_start as $k => $e) { 1091 1105 if(preg_match('@'.$e.'@i',$match[0][0])) { … … 1099 1113 if(preg_match('@' . $total_end[$idx] . '@i',$source,$match_end,PREG_OFFSET_CAPTURE,$offset + strlen($match[0][0]))) { 1100 1114 $en_len = strlen($match_end[0][0]); 1101 1102 //var_dump(substr($source,$offset,$match_end[0][1] - $offset + $en_len)); 1115 $captured_str = substr($source,$offset,$match_end[0][1] - $offset + $en_len); 1116 1117 // If this is a regex, grab any open square brackets inside the captured string, as we want to exclude using contents within to end the regex. 1118 if($idx === 'regex') { 1119 while(preg_match_all('@(?:(?<!\\\\)|(?<=^|[^\\\\])(?:\\\\{2})+)\\[([\\s\\S]*?(?:(?<!\\\\)|(?<=[^\\\\])(?:\\\\{2})+)\\])?@',$captured_str,$regex_match,PREG_OFFSET_CAPTURE)) { 1120 if(empty($regex_match[1][count($regex_match[1])-1])) { 1121 if(preg_match('@' . $total_end[$idx] . '@i',$source,$match_end,PREG_OFFSET_CAPTURE,$offset + strlen($captured_str))) { 1122 $captured_str = substr($source,$offset,$match_end[0][1] - $offset + $en_len); 1123 } else { 1124 // ERROR MESSAGE, end encapsulation tag not found. 1125 $ftype = $type === 'css' ? 'CSS' : 'Javascript'; 1126 trigger_error(sprintf('There is an error in your %s file. An encapsulator like a string or regex was opened and was not closed: %s.',$ftype,$captured_str),E_USER_ERROR); 1127 } 1128 } else break; 1129 } 1130 } 1131 1132 //var_dump($captured_str); 1103 1133 // If this is a comment, mark it for removal. 1104 1134 if(array_search($total_start[$idx],$comments_start) !== false) { 1105 array_push($comments_store, substr($source,$offset,$match_end[0][1] - $offset + $en_len));1135 array_push($comments_store,$captured_str); 1106 1136 } 1107 1137 … … 1110 1140 // ERROR MESSAGE, end encapsulation tag not found. 1111 1141 $ftype = $type === 'css' ? 'CSS' : 'Javascript'; 1112 trigger_error(sprintf('There is an error in your %s file. An encapsulator like a string or regex was opened and was not closed: %s.',$ftype, substr($source,$offset)),E_USER_ERROR);1142 trigger_error(sprintf('There is an error in your %s file. An encapsulator like a string or regex was opened and was not closed: %s.',$ftype,$captured_str),E_USER_ERROR); 1113 1143 } 1114 1144 -
html-minifier/trunk/readme.md
r1995957 r2001833 5 5 Requires at least: 3.6.4 6 6 Tested up to: 4.9.9 7 Stable tag: 2.3. 27 Stable tag: 2.3.3 8 8 Requires PHP: 5.4 9 9 License: GPLv2 or later … … 25 25 == Changelog == 26 26 27 = 2.3.3 = 28 *Release Date - 27 December 2018* 29 30 * Fixed a bug with Javascript comment removal where certain instances of minified regexes would cause the functionality to go haywire and terminate the file immaturely. 31 * The plugin should be WordPress 5.0 compatible now, but more testing will be needed before it is officially labelled as such. 32 27 33 = 2.3.2 = 28 34 *Release Date - 17 December 2018* 29 35 30 * Fixed a major string detectio in bug with the regex behind handling Javascript and CSS comments. This bug caused HTML Minifier to completely fail in minifying some Javascript and CSS files.36 * Fixed a major string detection bug with the regex behind handling Javascript and CSS comments. This bug caused HTML Minifier to completely fail in minifying some Javascript and CSS files. 31 37 * Found some issues with the plugin's compatibility with WordPress 5.0 and above, so the Tested Up To tag for this plugin was rolled back to 4.9.9. Apologies to the users who had to find this out the hard way! A proper compatibility patch for WordPress 5.0 will be released soon. 32 38
Note: See TracChangeset
for help on using the changeset viewer.