Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resolve #6 - don't minify non-javascript script content
anything in <script> tags that has a type that doesn't look like javascript will no longer be minified - add tests to confirm this is the case
- Loading branch information
Showing
5 changed files
with
92 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ HTML::Packer - Another HTML code cleaner | |
|
||
# VERSION | ||
|
||
Version 2.03 | ||
Version 2.04 | ||
|
||
# DESCRIPTION | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#!perl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use Test::More; | ||
|
||
eval 'use HTML::Packer;'; | ||
plan skip_all => 'HTML::Packer not installed!' if $@; | ||
|
||
plan tests => 20; | ||
|
||
SKIP: { | ||
|
||
foreach my $content_type ( | ||
'application/javascript', | ||
'application/ecmascript', | ||
'text/javascript', | ||
'text/ecmascript', | ||
'text/x-javascript', | ||
'application/x-javascript', | ||
'javascript', | ||
'', | ||
'text/template', | ||
'text/html', | ||
) { | ||
foreach my $attr_def ( | ||
" type=\"$content_type\"", | ||
" foo=\"bar\" type=\"$content_type\"", | ||
) { | ||
$attr_def =~ s/ type=""//; | ||
|
||
my $js_input = <<EOT; | ||
<script$attr_def> | ||
alert('test');</script> | ||
<a href="/" >link | ||
1 < /a> | ||
<!-- comment --> | ||
< a href="/"> link 2 | ||
< / a > | ||
EOT | ||
|
||
my $js_expected = "<script$attr_def>" . '/*<![CDATA[*/alert(\'test\');/*]]>*/</script> <a href="/">link 1 </a> <a href="/"> link 2 </a>'; | ||
my $js_expected_no_js = "<script$attr_def>" . "\n\n\n\n" . ' alert(\'test\');</script> <a href="/">link 1 </a> <a href="/"> link 2 </a>'; | ||
|
||
eval "use JavaScript::Packer $HTML::Packer::REQUIRED_JAVASCRIPT_PACKER;"; | ||
|
||
my $js_comp_input = $js_input; | ||
my $packer = HTML::Packer->init(); | ||
$packer->minify( | ||
\$js_comp_input, | ||
{ | ||
remove_comments => 1, | ||
remove_newlines => 1, | ||
do_javascript => 'clean' | ||
} | ||
); | ||
|
||
if ( $@ ) { | ||
is( $js_comp_input, $js_expected_no_js, 'Test do_javascript. JavaScript::Packer >= ' . $HTML::Packer::REQUIRED_JAVASCRIPT_PACKER . ' not installed.' ); | ||
} else { | ||
( !$content_type or $content_type !~ /script/ ) | ||
? is( $js_comp_input,$js_expected_no_js,"DO NOT minifiy for $content_type" ) | ||
: is( $js_comp_input,$js_expected, "minify for $content_type" ); | ||
} | ||
} | ||
} | ||
} |