HTML-Packer-2.11/000755 000765 000024 00000000000 14701720170 014712 5ustar00leejohnsonstaff000000 000000 HTML-Packer-2.11/Changes000644 000765 000024 00000006200 14701720031 016177 0ustar00leejohnsonstaff000000 000000 Revision history for HTML-Packer 2.11 2024-10-10 - Merge GH #19: fix unblessed reference (thanks to xvaara) 2.10 2020-01-13 - Merge GH #17: add support for Embedded ECMAScript Modules (thanks to ankitpati) 2.09 2019-07-17 - Merge GH #16: add support for CSP (thanks to ankitpati) 2.08 2019-07-14 - Merge GH #15: allow inheritance by avoiding __PACKAGE__ (thanks to ankitpati) 2.07 2018-04-03 - Fix GH #11: add remove_comments_aggressive options (thanks to girst) 2.06 2017-10-04 - Fix GH #8: proper newlines replacement (#9) (thanks to krizhanovsky) 2.05 2017-04-18 - Makefile.PL moved to ExtUtils::MakeMaker to fix no . in @INC (perl 5.25.11+) 2.04 2017-03-04 - Fix: don't minify none javascript script content (GH #6) 2.03 2016-05-22 - Fix: require recent versions of deps to fix memory leaks 2.02 2016-02-25 - Fix: memory leak due to reference cycles in reggrp_data closures 2.01 2016-01-13 - Fix: newlines should pack to spaces as per W3C (thanks to basbloemsaat) 2.00 2015-06-04 - New maintainer: LEEJO - Repoint issue tracker/repo at leejo's fork - Add .travis.yml for CI goodness - Add Changes test - Add MYMETA.json to .gitignore 1.004001 2012-02-20 - Use gnutar to build distribution. 1.004 2011-09-27 - Raised version number. 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. 1.002 2011-06-07 - Raised version number. 1.001_002 2011-05-20 - Fixed tests. Thanks to Kent Fredric. - Changed possible values for do_javascript options. 1.001_001 2011-04-12 - Added html5 option. - Removed no_cdata option. - Added tests. - Minor bugfixes. - Cleanup. 1.001001 2011-03-07 - Changed requirements to Regexp::RegGrp 1.000001 due to "undefined submatches bug" in Regexp::RegGrp. - Added accessors. - Added tests. 1.000 2011-01-17 - Changed versioning. - Raised major version due to changes in versioning. - Changed requirements to Regexp::RegGrp 1.000 due to changes in versioning. 0.05_06 2011-01-05 - Changed requirements to Regexp::RegGrp 0.04. 0.05_05 2010-12-03 - Added no_cdata option. 0.05_04 2010-10-05 - Changed required perl version to 5.8.9. 0.05_03 2010-09-21 - Added option to switch off compression via comment. - Added support for conditional comments. - Changed requirements to Regexp::RegGrp 0.0203 - Added tests. 0.05_02 2010-09-13 - Changed requirements to Regexp::RegGrp 0.0201 0.05_01 2009-02-15 - Moved regexp grouping stuff to Regexp::RegGrp. - Added object-oriented interface. - Switched tabs to soft tabs. - Switched to Module::Install. 0.4 2009-02-15 - Another embarrassing typo fix in documentation - Updated README file 0.3 2009-02-11 - Typo fix in documentation 0.2 2009-02-10 - Added some tests 0.1 2009-02-09 - First version, released on an unsuspecting world. HTML-Packer-2.11/MANIFEST000644 000765 000024 00000001213 14701720170 016040 0ustar00leejohnsonstaff000000 000000 Changes lib/HTML/Packer.pm Makefile.PL MANIFEST README.md t/00-load.t t/01-interface.t t/02-io.t t/03-leaks.t t/04-leaks_full.t t/gh-6_exempt_some_script_tags.t t/gh-16_content_security_policy_hashes.t t/html/s1-expected.html t/html/s1.html t/html/s2-expected.html t/html/s2.html t/html/s3-expected.html t/html/s3.html t/html/s4-expected.html t/html/s4.html t/html/s5-expected.html t/html/s5.html t/html/s6-expected.html t/html/s6.html t/html/s7-expected.html t/html/s7.html t/pod.t META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) HTML-Packer-2.11/t/000755 000765 000024 00000000000 14701720170 015155 5ustar00leejohnsonstaff000000 000000 HTML-Packer-2.11/META.yml000644 000765 000024 00000001534 14701720170 016166 0ustar00leejohnsonstaff000000 000000 --- abstract: 'Another HTML code cleaner' author: - 'Lee Johnson ' build_requires: Test::More: '0' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 7.62, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: HTML-Packer no_index: directory: - t - inc requires: CSS::Packer: '2.01' Digest::SHA: '0' JavaScript::Packer: '2.01' Regexp::RegGrp: 1.001_001 Safe::Isa: '0' resources: bugtracker: https://github.com/leejo/html-packer-perl/issues homepage: https://metacpan.org/module/HTML::Packer license: http://dev.perl.org/licenses/ repository: https://github.com/leejo/html-packer-perl version: '2.11' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' HTML-Packer-2.11/META.json000644 000765 000024 00000002612 14701720170 016334 0ustar00leejohnsonstaff000000 000000 { "abstract" : "Another HTML code cleaner", "author" : [ "Lee Johnson " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 7.62, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "HTML-Packer", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "Test::More" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "CSS::Packer" : "2.01", "Digest::SHA" : "0", "JavaScript::Packer" : "2.01", "Regexp::RegGrp" : "1.001_001", "Safe::Isa" : "0" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/leejo/html-packer-perl/issues" }, "homepage" : "https://metacpan.org/module/HTML::Packer", "license" : [ "http://dev.perl.org/licenses/" ], "repository" : { "url" : "https://github.com/leejo/html-packer-perl" } }, "version" : "2.11", "x_serialization_backend" : "JSON::PP version 4.06" } HTML-Packer-2.11/README.md000644 000765 000024 00000007361 14701720041 016175 0ustar00leejohnsonstaff000000 000000 # NAME HTML::Packer - Another HTML code cleaner
Build Status Coverage Status
# VERSION Version 2.11 # DESCRIPTION A HTML Compressor. # SYNOPSIS use HTML::Packer; my $packer = HTML::Packer->init(); $packer->minify( $scalarref, $opts ); To return a scalar without changing the input simply use (e.g. example 2): my $ret = $packer->minify( $scalarref, $opts ); For backward compatibility it is still possible to call 'minify' as a function: HTML::Packer::minify( $scalarref, $opts ); First argument must be a scalarref of HTML-Code. Second argument must be a hashref of options. Possible options are - remove\_comments HTML-Comments will be removed if 'remove\_comments' has a true value. Comments starting with ` Is not set by default. - html5 If set to a true value closing slashes will be removed from void elements. - csp If `do_csp` is set to `'sha256'`, returns a hash that looks like this: ( 'script-src' => [qw( sha256-...= sha256-...= )], 'style-src' => [qw( sha256-...= sha256-...= )], ) with each element of the `ARRAY`refs containing a CSP-friendly hash for a ` Hello, World! EOS }, { description => 'multiple Hello, World! EOS }, { description => 'multiple Hello, World! EOS }, { description => 'multiple Hello, World! EOS }, { description => 'unknown hash algorithm (no hash calculated)', config => { do_csp => 'unknown435', }, csp => { 'script-src' => [qw( )], 'style-src' => [qw( )], }, html => <<'EOS', Hello! Hello, World! EOS }, ); foreach my $test ( @tests ) { my $packer = HTML::Packer->init; my $html = $test->{html}; $packer->minify( \$html, $test->{config} ); is_deeply( { $packer->csp }, $test->{csp}, $test->{description} ); } HTML-Packer-2.11/t/04-leaks_full.t000644 000765 000024 00000003736 14701717526 017730 0ustar00leejohnsonstaff000000 000000 #!perl use strict; use warnings; use Test::More; use HTML::Packer; if (! eval "use Test::Memory::Cycle; 1;" ) { plan skip_all => 'Test::Memory::Cycle required for this test'; } my $packer = HTML::Packer->init; memory_cycle_ok( $packer ); my $row = q@ Me me @; for ( 1 .. 5 ) { my %opts = ( remove_newlines => "true", remove_comments => 'true', do_javascript => 'best', do_stylesheet => 'minify' ); ok( $packer->minify( \$row,\%opts ),'minify' ); } memory_cycle_ok( $packer ); done_testing(); HTML-Packer-2.11/t/html/000755 000765 000024 00000000000 14701720170 016121 5ustar00leejohnsonstaff000000 000000 HTML-Packer-2.11/t/00-load.t000644 000765 000024 00000000222 14701717526 016505 0ustar00leejohnsonstaff000000 000000 #!perl -T use Test::More tests => 1; BEGIN { use_ok( 'HTML::Packer' ); } diag( "Testing HTML::Packer $HTML::Packer::VERSION, Perl $], $^X" ); HTML-Packer-2.11/t/03-leaks.t000644 000765 000024 00000000654 14701717526 016701 0ustar00leejohnsonstaff000000 000000 #!perl use strict; use warnings; use Test::More; use HTML::Packer; if (! eval "use Test::Memory::Cycle; 1;" ) { plan skip_all => 'Test::Memory::Cycle required for this test'; } my $packer = HTML::Packer->init; memory_cycle_ok( $packer ); my $row = " Foo"; for ( 1 .. 5 ) { ok( $packer->minify( \$row,{} ),'minify' ); } memory_cycle_ok( $packer ); done_testing(); HTML-Packer-2.11/t/02-io.t000644 000765 000024 00000014706 14701717526 016213 0ustar00leejohnsonstaff000000 000000 #!perl -T # =========================================================================== # use Test::More; my $js_input = < alert('test'); link 1 < /a> < a href="/"> link 2 < / a > EOT my $js_expected = ' link 1 link 2 '; my $js_expected_html5 = ' link 1 link 2 '; my $js_expected_html5_no_js = ' link 1 link 2 '; my $js_expected_no_js = ' link 1 link 2 '; my $css_input = < foo { asdf:asdf; ew:12; } link 1 < /a> < a href="/"> link 2 < / a > EOT my $css_expected = ' link 1 link 2 '; my $css_expected_no_css = ' link 1 link 2 '; my $css_expected_html5 = ' link 1 link 2 '; my $css_expected_html5_no_css = ' link 1 link 2 '; my $html_input = </**/
hmpf link 1 < /a> < a href="/"> link 2 < / a > EOT my $html_expected = '
hmpf
link 1 link 2 '; my $html_expected_no_js = '
hmpf link 1 link 2 '; my $not = 12; SKIP: { eval { use HTML::Packer; }; skip( 'HTML::Packer not installed!', $not ) if ( $@ ); plan tests => $not; minTest( 's1', undef, 'Test without opts.' ); minTest( 's2', { remove_newlines => 1 }, 'Test remove_newlines.' ); minTest( 's3', { remove_comments => 1 }, 'Test remove_comments.' ); minTest( 's4', { remove_comments => 1, remove_newlines => 1 }, 'Test remove_newlines and remove_comments.' ); minTest( 's5', { remove_comments => 1, remove_newlines => 1 }, 'Test _no_compress_ comment.' ); minTest( 's6', { remove_comments => 1, remove_newlines => 1, no_compress_comment => 1 }, 'Test _no_compress_ comment with no_compress_comment option.' ); minTest( 's7', { remove_comments_aggressive => 1 }, 'Test aggresive comment removal.' ); my $packer = HTML::Packer->init(); my $js_comp_input = $js_input; my $js_html5_input = $js_input; $packer->minify( \$js_comp_input, { remove_comments => 1, remove_newlines => 1, do_javascript => 'clean' } ); $packer->minify( \$js_html5_input, { remove_comments => 1, remove_newlines => 1, do_javascript => 'clean', html5 => 1 } ); $packer->minify( \$html_input, { remove_comments => 1, remove_newlines => 1, do_javascript => 'clean', html5 => 1 } ); eval "use JavaScript::Packer $HTML::Packer::REQUIRED_JAVASCRIPT_PACKER;"; if ( $@ ) { is( $js_comp_input, $js_expected_no_js, 'Test do_javascript. JavaScript::Packer >= ' . $HTML::Packer::REQUIRED_JAVASCRIPT_PACKER . ' not installed.' ); is( $js_html5_input, $js_expected_html5_no_js, 'Test do_javascript 2. JavaScript::Packer >= ' . $HTML::Packer::REQUIRED_JAVASCRIPT_PACKER . ' not installed.' ); is( $html_input, $html_expected_no_js, 'Test do_javascript 3. JavaScript::Packer >= ' . $HTML::Packer::REQUIRED_JAVASCRIPT_PACKER . ' not installed.' ); } else { is( $js_comp_input, $js_expected, 'Test do_javascript. JavaScript::Packer installed.' ); is( $js_html5_input, $js_expected_html5, 'Test do_javascript 2. JavaScript::Packer installed.' ); is( $html_input, $html_expected, 'Test do_javascript 3. JavaScript::Packer installed.' ); } 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_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_comp_input, $css_expected, 'Test do_stylesheet. CSS::Packer installed.' ); is( $css_html5_input, $css_expected_html5, 'Test do_stylesheet 2. CSS::Packer installed.' ); } } sub filesMatch { my $file1 = shift; my $file2 = shift; my $a; my $b; while (1) { $a = getc($file1); $b = getc($file2); if (!defined($a) && !defined($b)) { # both files end at same place return 1; } elsif ( !defined($b) || # file2 ends first !defined($a) || # file1 ends first $a ne $b ) { # a and b not the same return 0; } } } sub minTest { my $filename = shift; my $opts = shift || {}; my $message = shift || ''; open(INFILE, 't/html/' . $filename . '.html') or die("couldn't open file"); open(GOTFILE, '>t/html/' . $filename . '-got.html') or die("couldn't open file"); my $html = join( '', ); my $packer = HTML::Packer->init(); $packer->minify( \$html, $opts ); print GOTFILE $html; close(INFILE); close(GOTFILE); open(EXPECTEDFILE, 't/html/' . $filename . '-expected.html') or die("couldn't open file"); open(GOTFILE, 't/html/' . $filename . '-got.html') or die("couldn't open file"); ok(filesMatch(GOTFILE, EXPECTEDFILE), $message ); close(EXPECTEDFILE); close(GOTFILE); } HTML-Packer-2.11/t/gh-6_exempt_some_script_tags.t000644 000765 000024 00000004132 14701717526 023125 0ustar00leejohnsonstaff000000 000000 #!perl use strict; use warnings; use Test::More; eval 'use HTML::Packer;'; plan skip_all => 'HTML::Packer not installed!' if $@; eval "use JavaScript::Packer $HTML::Packer::REQUIRED_JAVASCRIPT_PACKER;"; plan skip_all => "JavaScript::Packer $HTML::Packer::REQUIRED_JAVASCRIPT_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 = < alert('test'); link 1 < /a> < a href="/"> link 2 < / a > EOT my $js_expected = "" . '/**/ link 1 link 2 '; my $js_expected_no_js = "" . "\n\n\n\n" . ' alert(\'test\'); link 1 link 2 '; 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" ); } } } } HTML-Packer-2.11/t/html/s4.html000644 000765 000024 00000000143 14701717526 017346 0ustar00leejohnsonstaff000000 000000 link 1 < /a> < a href="/"> link 2 < / a > HTML-Packer-2.11/t/html/s4-expected.html000644 000765 000024 00000000060 14701717526 021143 0ustar00leejohnsonstaff000000 000000 link 1 link 2 HTML-Packer-2.11/t/html/s3-expected.html000644 000765 000024 00000000420 14701717526 021142 0ustar00leejohnsonstaff000000 000000 link 1 link 2 link 3 1 link 4 HTML-Packer-2.11/t/html/s5.html000644 000765 000024 00000000202 14701717526 017343 0ustar00leejohnsonstaff000000 000000 link 1 < /a> < a href="/"> link 2 < / a > HTML-Packer-2.11/t/html/s7-expected.html000644 000765 000024 00000000143 14701717526 021150 0ustar00leejohnsonstaff000000 000000 link 1 link 2 link 3 1 link 4 HTML-Packer-2.11/t/html/s2.html000644 000765 000024 00000000475 14701717526 017354 0ustar00leejohnsonstaff000000 000000 bla bla link 1 < /a> < a href="/"> link 2 < / a > The database employs a number of cutting-edge technologies such as cache- conscious lock-free burst hash trie for the index, NUMA-aware records distribution and replication, and so on. HTML-Packer-2.11/t/html/s3.html000644 000765 000024 00000000547 14701717526 017355 0ustar00leejohnsonstaff000000 000000 link 1 < /a> < a href="/"> link 2 < / a > link 3 1 < /a> < a href="/"> link 4 < / a > HTML-Packer-2.11/t/html/s1.html000644 000765 000024 00000000170 14701717526 017343 0ustar00leejohnsonstaff000000 000000 link 1 < /a> < a href="/"> link 2 < / a > HTML-Packer-2.11/t/html/s6.html000644 000765 000024 00000000202 14701717526 017344 0ustar00leejohnsonstaff000000 000000 link 1 < /a> < a href="/"> link 2 < / a > HTML-Packer-2.11/t/html/s6-expected.html000644 000765 000024 00000000060 14701717526 021145 0ustar00leejohnsonstaff000000 000000 link 1 link 2 HTML-Packer-2.11/t/html/s2-expected.html000644 000765 000024 00000000430 14701717526 021142 0ustar00leejohnsonstaff000000 000000 blabla link 1 link 2 The database employs a number of cutting-edge technologies such as cache-conscious lock-free burst hash trie for the index, NUMA-aware records distribution and replication, and so on.HTML-Packer-2.11/t/html/s5-expected.html000644 000765 000024 00000000202 14701717526 021142 0ustar00leejohnsonstaff000000 000000 link 1 < /a> < a href="/"> link 2 < / a > HTML-Packer-2.11/t/html/s1-expected.html000644 000765 000024 00000000124 14701717526 021141 0ustar00leejohnsonstaff000000 000000 link 1 link 2 HTML-Packer-2.11/t/html/s7.html000644 000765 000024 00000000547 14701717526 017361 0ustar00leejohnsonstaff000000 000000 link 1 < /a> < a href="/"> link 2 < / a > link 3 1 < /a> < a href="/"> link 4 < / a >