Permalink
Browse files

Version 1.003_001

- Replaced map with foreach.
- Fixed bug in html5 handling. Thanks to Brian Cassidy.
  • Loading branch information...
1 parent 22466e3 commit 7074d1efb450957692adfc8d18f1e807bd195ff6 Merten Falk committed Jul 18, 2011
Showing with 31 additions and 14 deletions.
  1. +5 −1 Changes
  2. +10 −7 lib/HTML/Packer.pm
  3. +16 −6 t/02-io.t
View
@@ -1,6 +1,10 @@
Revision history for HTML-Packer
-1.002001 2001-06-15
+1.003_001 2011-08-19
+ - Replaced map with foreach.
+ - Fixed bug in html5 handling. Thanks to Brian Cassidy.
+
+1.002001 2011-06-15
- Fixed embarrassing bug in comment regexp.
- Fixed tests.
- Added TODO.
View
@@ -8,7 +8,7 @@ use Regexp::RegGrp;
# -----------------------------------------------------------------------------
-our $VERSION = '1.002001';
+our $VERSION = '1.003_001';
our @BOOLEAN_ACCESSORS = (
'remove_comments',
@@ -236,9 +236,10 @@ sub init {
my ( $opening, undef, $content, $closing ) = @{$_[0]->{submatches}};
if ( $content ) {
- my $opening_re = '<\s*script' . ( $self->html5() ? '[^>]*>' : '[^>]*(?:java|ecma)script[^>]*>' );
+ my $opening_script_re = '<\s*script' . ( $self->html5() ? '[^>]*>' : '[^>]*(?:java|ecma)script[^>]*>' );
+ my $opening_style_re = '<\s*style' . ( $self->html5() ? '[^>]*>' : '[^>]*text\/css[^>]*>' );
- if ( $opening =~ /$opening_re/i ) {
+ if ( $opening =~ /$opening_script_re/i ) {
$opening =~ s/ type="(text\/)?(java|ecma)script"//i if ( $self->html5() );
if ( $self->javascript_packer() and $self->do_javascript() ) {
@@ -249,7 +250,9 @@ sub init {
}
}
}
- elsif ( $opening =~ /<\s*style[^>]*text\/css[^>]*>/ ) {
+ elsif ( $opening =~ /$opening_style_re/i ) {
+ $opening =~ s/ type="text\/css"//i if ( $self->html5() );
+
if ( $self->css_packer() and $self->do_stylesheet() ) {
$self->css_packer()->minify( \$content, { compress => $self->do_stylesheet() } );
$content = "\n" . $content if ( $self->do_stylesheet() eq 'pretty' );
@@ -279,9 +282,9 @@ sub init {
}
];
- map {
+ foreach ( @HTML::Packer::REGGRPS ) {
$self->{ '_reggrp_' . $_ } = Regexp::RegGrp->new( { reggrp => $self->{$_}->{reggrp_data} } );
- } @REGGRPS;
+ }
$self->{ '_reggrp_' . $GLOBAL_REGGRP } = Regexp::RegGrp->new(
{
@@ -405,7 +408,7 @@ HTML::Packer - Another HTML code cleaner
=head1 VERSION
-Version 1.002001
+Version 1.003_001
=head1 DESCRIPTION
View
@@ -28,6 +28,7 @@ EOT
my $js_expected = '<script type="javascript">/*<![CDATA[*/alert(\'test\');/*]]>*/</script> <a href="/">link 1 </a> <a href="/"> link 2 </a>';
my $js_expected_html5 = '<script>alert(\'test\');</script> <a href="/">link 1 </a> <a href="/"> link 2 </a>';
+
my $js_expected_html5_no_js = '<script>' . "\n\n\n\n" . ' alert(\'test\');</script> <a href="/">link 1 </a> <a href="/"> link 2 </a>';
my $js_expected_no_js = '<script type="javascript">' . "\n\n\n\n" . ' alert(\'test\');</script> <a href="/">link 1 </a> <a href="/"> link 2 </a>';
@@ -55,8 +56,11 @@ my $css_input = <<EOT;
EOT
-my $css_expected = '<style type="text/css">' . "\nfoo{\nasdf:asdf;\new:12;\n}\n" . '</style> <a href="/">link 1 </a> <a href="/"> link 2 </a>';
-my $css_expected_no_css = '<style type="text/css">' . "\n\n foo {\n asdf:asdf;\n ew:12;\n }\n" . '</style> <a href="/">link 1 </a> <a href="/"> link 2 </a>';
+my $css_expected = '<style type="text/css">' . "\nfoo{\nasdf:asdf;\new:12;\n}\n" . '</style> <a href="/">link 1 </a> <a href="/"> link 2 </a>';
+my $css_expected_no_css = '<style type="text/css">' . "\n\n foo {\n asdf:asdf;\n ew:12;\n }\n" . '</style> <a href="/">link 1 </a> <a href="/"> link 2 </a>';
+
+my $css_expected_html5 = '<style>' . "\nfoo{\nasdf:asdf;\new:12;\n}\n" . '</style> <a href="/">link 1 </a> <a href="/"> link 2 </a>';
+my $css_expected_html5_no_css = '<style>' . "\n\n foo {\n asdf:asdf;\n ew:12;\n }\n" . '</style> <a href="/">link 1 </a> <a href="/"> link 2 </a>';
my $html_input = <<EOT;
<script type="javascript">/*<![CDATA[*/
@@ -81,7 +85,7 @@ EOT
my $html_expected = '<script>alert(\'test\');</script><br><img src="/bild.jpg" alt="hmpf"> <a href="/">link 1 </a> <a href="/"> link 2 </a>';
my $html_expected_no_js = '<script>/*<![CDATA[*/' . "\n\n\n\n " . 'alert(\'test\');/*]]>*/</script><br><img src="/bild.jpg" alt="hmpf"> <a href="/">link 1 </a> <a href="/"> link 2 </a>';
-my $not = 10;
+my $not = 11;
SKIP: {
eval { use HTML::Packer; };
@@ -116,14 +120,20 @@ SKIP: {
is( $html_input, $html_expected, 'Test do_javascript 3. JavaScript::Packer installed.' );
}
- $packer->minify( \$css_input, { remove_comments => 1, remove_newlines => 1, do_stylesheet => 'pretty' } );
+ my $css_comp_input = $css_input;
+ my $css_html5_input = $css_input;
+
+ $packer->minify( \$css_comp_input, { remove_comments => 1, remove_newlines => 1, do_stylesheet => 'pretty', html5 => 0 } );
+ $packer->minify( \$css_html5_input, { remove_comments => 1, remove_newlines => 1, do_stylesheet => 'pretty', html5 => 1 } );
eval "use CSS::Packer $HTML::Packer::REQUIRED_CSS_PACKER;";
if ( $@ ) {
- is( $css_input, $css_expected_no_css, 'Test do_stylesheet. CSS::Packer >= ' . $HTML::Packer::REQUIRED_CSS_PACKER . ' not installed.' );
+ is( $css_comp_input, $css_expected_no_css, 'Test do_stylesheet. CSS::Packer >= ' . $HTML::Packer::REQUIRED_CSS_PACKER . ' not installed.' );
+ is( $css_html5_input, $css_expected_html5_no_css, 'Test do_stylesheet 2. CSS::Packer >= ' . $HTML::Packer::REQUIRED_CSS_PACKER . ' not installed.' );
}
else {
- is( $css_input, $css_expected, 'Test do_stylesheet. CSS::Packer installed.' );
+ is( $css_comp_input, $css_expected, 'Test do_stylesheet. CSS::Packer installed.' );
+ is( $css_html5_input, $css_expected_html5, 'Test do_stylesheet 2. CSS::Packer installed.' );
}
}

0 comments on commit 7074d1e

Please sign in to comment.