-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error with trailing unclosed comments #23
Comments
I'm experimenting with this approach: diff --git a/cssmin.php b/cssmin.php
index fab0102..ac01811 100644
--- a/cssmin.php
+++ b/cssmin.php
@@ -75,9 +75,22 @@ class CSSmin
$css = $this->extract_data_urls($css);
+ // Clean up trailing unclosed comments
+ $last_newline = strrpos( rtrim( $css ), "\n" );
+ if ( $last_newline !== false ) {
+ $last_comment_start = strrpos( $css, '/*', $last_newline );
+ if ( $last_comment_start !== false ) {
+ $last_comment_end = strrpos( $css, '*/', $last_comment_start );
+ if ( $last_comment_end === false ) {
+ $css = substr( $css, 0, $last_newline );
+ }
+ }
+ }
+
// collect all comment blocks...
while (($start_index = $this->index_of($css, '/*', $start_index)) >= 0)
$end_index = $this->index_of($css, '*/', $start_index + 2);
+
if ($end_index < 0) {
$end_index = $length;
}
@@ -774,4 +787,4 @@ class CSSmin
return (int) $size;
}
-}
\ No newline at end of file
+}
a {
color: blue;
}
html >/**/ body p {
color: blue;
/*a comment right before the IE star hack*/*width:auto;
height:2%;
}
/* Comment 1 */
/* Comment 2
a{color:blue}html>/**/body p{color:blue;*width:auto;height:2%} |
Although I agree I could take a defensive approach to fix that weird case I also think it's a coder's responsibility to have his code linted and checked before doing anything else with it. So, thank you very much for your time and code but that's an issue I won't fix ;) |
On v3.0.0, which is about to be released in a few days, the minifier will not hang when it encounters a unclosed comment 👍 |
so what else will be in 3.0.0 @tubalmartin ? :-) |
Fixed in v2.4.8-p10 & v3.0.0 |
I ran into a problem with CSSmin hanging during the minification process. Eventually I tracked it down to a problem with an unclosed comment at the end of the file. It can be reproduced with this CSS:
When I run CSSmin against this it does the infinite loop thing until hitting the max execution time limit in PHP.
Yes the error is that user didn't close the comment, but I think a defensive approach would be to strip the unclosed trailing comment out.
The text was updated successfully, but these errors were encountered: