HTML-Scrubber-0.11000755000765000024 012226003500 13314 5ustar00nigelstaff000000000000README100644000765000024 2412112226003500 14275 0ustar00nigelstaff000000000000HTML-Scrubber-0.11NAME HTML::Scrubber - Perl extension for scrubbing/sanitizing html VERSION version 0.11 SYNOPSIS use HTML::Scrubber; my $scrubber = HTML::Scrubber->new( allow => [ qw[ p b i u hr br ] ] ); print $scrubber->scrub('

bold missing

'); # output is:

bold

# more complex input my $html = q[
a => link br =>
b => bold u => UNDERLINE ]; print $scrubber->scrub($html); $scrubber->deny( qw[ p b i u hr br ] ); print $scrubber->scrub($html); DESCRIPTION If you want to "scrub" or "sanitize" html input in a reliable and flexible fashion, then this module is for you. I wasn't satisfied with HTML::Sanitizer because it is based on HTML::TreeBuilder, so I thought I'd write something similar that works directly with HTML::Parser. METHODS First a note on documentation: just study the EXAMPLE below. It's all the documentation you could need Also, be sure to read all the comments as well as How does it work?. If you're new to perl, good luck to you. comment warn "comments are ", $p->comment ? 'allowed' : 'not allowed'; $p->comment(0); # off by default process warn "process instructions are ", $p->process ? 'allowed' : 'not allowed'; $p->process(0); # off by default script warn "script tags (and everything in between) are supressed" if $p->script; # off by default $p->script( 0 || 1 ); ** Please note that this is implemented using HTML::Parser's ignore_elements function, so if "script" is set to true, all script tags encountered will be validated like all other tags. style warn "style tags (and everything in between) are supressed" if $p->style; # off by default $p->style( 0 || 1 ); ** Please note that this is implemented using HTML::Parser's ignore_elements function, so if "style" is set to true, all style tags encountered will be validated like all other tags. allow $p->allow(qw[ t a g s ]); deny $p->deny(qw[ t a g s ]); rules $p->rules( img => { src => qr{^(?!http://)}i, # only relative image links allowed alt => 1, # alt attribute allowed '*' => 0, # deny all other attributes }, a => { href => sub { ... }, # check or adjust with a callback }, b => 1, ... ); Updates set of attribute rules. Each rule can be 1/0, regular expression or a callback. Values longer than 1 char are treated as regexps. Callback is called with the following arguments: this object, tag name, attribute name and attribute value, should return empty list to drop attribute, "undef" to keep it without value or a new scalar value. default print "default is ", $p->default(); $p->default(1); # allow tags by default $p->default( undef, # don't change { # default attribute rules '*' => 1, # allow attributes by default } ); scrub_file $html = $scrubber->scrub_file('foo.html'); ## returns giant string die "Eeek $!" unless defined $html; ## opening foo.html may have failed $scrubber->scrub_file('foo.html', 'new.html') or die "Eeek $!"; $scrubber->scrub_file('foo.html', *STDOUT) or die "Eeek $!" if fileno STDOUT; scrub print $scrubber->scrub($html); ## returns giant string $scrubber->scrub($html, 'new.html') or die "Eeek $!"; $scrubber->scrub($html', *STDOUT) or die "Eeek $!" if fileno STDOUT; *default* handler, used by both _scrub and _scrub_fh Moved all the common code (basically all of it) into a single routine for ease of maintenance *default* handler, does the scrubbing if we're scrubbing out to a file. Now calls _scrub_str and pushes that out to a file. *default* handler, does the scrubbing if we're returning a giant string. Now calls _scrub_str and appends that to the output string. How does it work? When a tag is encountered, HTML::Scrubber allows/denies the tag using the explicit rule if one exists. If no explicit rule exists, Scrubber applies the default rule. If an explicit rule exists, but it's a simple rule(1), the default attribute rule is applied. EXAMPLE #!/usr/bin/perl -w use HTML::Scrubber; use strict; my @allow = qw[ br hr b a ]; my @rules = ( script => 0, img => { src => qr{^(?!http://)}i, # only relative image links allowed alt => 1, # alt attribute allowed '*' => 0, # deny all other attributes }, ); my @default = ( 0 => # default rule, deny all tags { '*' => 1, # default rule, allow all attributes 'href' => qr{^(?:http|https|ftp)://}i, 'src' => qr{^(?:http|https|ftp)://}i, # If your perl doesn't have qr # just use a string with length greater than 1 'cite' => '(?i-xsm:^(?:http|https|ftp):)', 'language' => 0, 'name' => 1, # could be sneaky, but hey ;) 'onblur' => 0, 'onchange' => 0, 'onclick' => 0, 'ondblclick' => 0, 'onerror' => 0, 'onfocus' => 0, 'onkeydown' => 0, 'onkeypress' => 0, 'onkeyup' => 0, 'onload' => 0, 'onmousedown' => 0, 'onmousemove' => 0, 'onmouseout' => 0, 'onmouseover' => 0, 'onmouseup' => 0, 'onreset' => 0, 'onselect' => 0, 'onsubmit' => 0, 'onunload' => 0, 'src' => 0, 'type' => 0, } ); my $scrubber = HTML::Scrubber->new(); $scrubber->allow( @allow ); $scrubber->rules( @rules ); # key/value pairs $scrubber->default( @default ); $scrubber->comment(1); # 1 allow, 0 deny ## preferred way to create the same object $scrubber = HTML::Scrubber->new( allow => \@allow, rules => \@rules, default => \@default, comment => 1, process => 0, ); require Data::Dumper,die Data::Dumper::Dumper($scrubber) if @ARGV; my $it = q[
IN ITALICS WITH FAKE="attribute"
IN BOLD
HREF=JAVA <!>
ONMOUSEOVER JAVASCRIPT
]; print "#original text",$/, $it, $/; print "#scrubbed text (default ", $scrubber->default(), # no arguments returns the current value " comment ", $scrubber->comment(), " process ", $scrubber->process(), " )", $/, $scrubber->scrub($it), $/; $scrubber->default(1); # allow all tags by default $scrubber->comment(0); # deny comments print "#scrubbed text (default ", $scrubber->default(), " comment ", $scrubber->comment(), " process ", $scrubber->process(), " )", $/, $scrubber->scrub($it), $/; $scrubber->process(1); # allow process instructions (dangerous) $default[0] = 1; # allow all tags by default $default[1]->{'*'} = 0; # deny all attributes by default $scrubber->default(@default); # set the default again print "#scrubbed text (default ", $scrubber->default(), " comment ", $scrubber->comment(), " process ", $scrubber->process(), " )", $/, $scrubber->scrub($it), $/; FUN If you have Test::Inline (and you've installed HTML::Scrubber), try pod2test Scrubber.pm >scrubber.t perl scrubber.t SEE ALSO HTML::Parser, Test::Inline, HTML::Sanitizer. INSTALLATION See perlmodinstall for information and options on installing Perl modules. BUGS AND LIMITATIONS You can make new bug reports, and view existing ones, through the web interface at . AVAILABILITY The project homepage is . The latest version of this module is available from the Comprehensive Perl Archive Network (CPAN). Visit to find a CPAN site near you, or see . AUTHORS * Ruslan Zakirov * Nigel Metheringham * D. H. COPYRIGHT AND LICENSE This software is copyright (c) 2013 by Ruslan Zakirov, Nigel Metheringham, 2003-2004 D. H.. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Changes100644000765000024 427412226003500 14677 0ustar00nigelstaff000000000000HTML-Scrubber-0.11Revision history for Perl extension HTML::Scrubber. 0.11 2013-10-11 15:11:59 Europe/London 0.10 2013-09-27 15:05:03 Europe/London - RT3008 Changed examples to be XSS free - RT19063, RT25477 fixed handling of self closing tags, for example '
' - * attribute rule can be a regexp - callbacks in rules to check or adjust attributes with custom code (RT15747) 0.09 2011-04-01 16:35:50 Europe/London - Basic conversion to Dist::Zilla/git - Tidies to keep Perl::Critic happier - Removed use of naked filehandles - Reworked tests to not use predicable temp file name - Collapsed duplicate code to a single version - Various documentation tweaks - Change of maintainer as PODMASTER cannot be contacted 0.08 Thu Apr 1 14:14:38 2004 - removed test which relied on stuff that changed in HTML-Parser-3.36 0.07 Thu Mar 18 06:21:38 2004 - allow for boolean attributes (thanks b10m) - which is why now attribute order is followed (attrseq) repeated elements get squashed (see 07_booleans.t for details). 0.06 Sun Nov 2 01:26:42 2003 - fixed more typos - added t\06_scrub_file.t (that part was broken, now fixed) 0.05 Thu Oct 30 23:27:37 2003 - fixed up various typos in tests ... - bumped up version number ;( 0.04 Wed Oct 29 18:35:08 2003 - added missing lc in a few places (and got rid of for @_) - fixed (and improved) optimizations (stupid typo) - added DESTROY to break circular reference (I lost my TODO, so i forgot) - added more pod (allow deny ...) - improved test suite - added LICENSE file - added script/style functions (nice) 0.03 Mon Jul 21 07:32:10 2003 - perltidy ;) - closed http://rt.cpan.org/NoAuth/Bug.html?id=2969 now escape spurious >< in text - updated test.pl 0.02 Fri Apr 18 14:12:02 2003 - finished TODO, settled on API - created a cpan worthy distribution and uploaded to CPAN 0.01 Thu Apr 17 20:34:11 2003 - original version; created by h2xs 1.21 with options -AX HTML::Scrubber - wrote initial version and released at http://perlmonks.org/index.pl?node_id=251427 LICENSE100644000765000024 4404012226003500 14424 0ustar00nigelstaff000000000000HTML-Scrubber-0.11This software is copyright (c) 2013 by Ruslan Zakirov, Nigel Metheringham, 2003-2004 D. H.. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2013 by Ruslan Zakirov, Nigel Metheringham, 2003-2004 D. H.. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Suite 500, Boston, MA 02110-1335 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2013 by Ruslan Zakirov, Nigel Metheringham, 2003-2004 D. H.. This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End INSTALL100644000765000024 171212226003500 14427 0ustar00nigelstaff000000000000HTML-Scrubber-0.11 This is the Perl distribution HTML-Scrubber. Installing HTML-Scrubber is straightforward. ## Installation with cpanm If you have cpanm, you only need one line: % cpanm HTML::Scrubber If you are installing into a system-wide directory, you may need to pass the "-S" flag to cpanm, which uses sudo to install the module: % cpanm -S HTML::Scrubber ## Installing with the CPAN shell Alternatively, if your CPAN shell is set up, you should just be able to do: % cpan HTML::Scrubber ## Manual installation As a last resort, you can manually install it. Download the tarball, untar it, then build it: % perl Build.PL % ./Build && ./Build test Then install it: % ./Build install If you are installing into a system-wide directory, you may need to run: % sudo ./Build install ## Documentation HTML-Scrubber documentation is available as POD. You can run perldoc from a shell to read the documentation: % perldoc HTML::Scrubber META.yml100644000765000024 1725612226003500 14701 0ustar00nigelstaff000000000000HTML-Scrubber-0.11--- abstract: 'Perl extension for scrubbing/sanitizing html' author: - 'Ruslan Zakirov ' - 'Nigel Metheringham ' - 'D. H. ' build_requires: Carp: 0 File::Spec: 0 File::Temp: 0 IO::Handle: 0 IPC::Open3: 0 Module::Build: 0.3601 Scalar::Util: 0 Test: 0 Test::More: 0.94 perl: 5.004 utf8: 0 configure_requires: Module::Build: 0.3601 dynamic_config: 0 generated_by: 'Dist::Zilla version 4.300039, CPAN::Meta::Converter version 2.132661' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: HTML-Scrubber provides: HTML::Scrubber: file: lib/HTML/Scrubber.pm version: 0.11 requires: HTML::Entities: 0 HTML::Parser: 3.47 strict: 0 warnings: 0 resources: bugtracker: http://rt.cpan.org/Public/Dist/Display.html?Name=HTML-Scrubber homepage: https://metacpan.org/release/HTML-Scrubber repository: git://github.com/nigelm/html-scrubber.git version: 0.11 x_Dist_Zilla: perl: version: 5.018001 plugins: - class: Dist::Zilla::Plugin::Git::NextVersion name: '@NIGELM/Git::NextVersion' version: 2.014 - class: Dist::Zilla::Plugin::Git::Check name: '@NIGELM/Git::Check' version: 2.014 - class: Dist::Zilla::Plugin::GatherDir name: '@NIGELM/GatherDir' version: 4.300039 - class: Dist::Zilla::Plugin::Test::Compile config: Dist::Zilla::Plugin::Test::Compile: module_finder: - ':InstallModules' script_finder: - ':ExecFiles' name: '@NIGELM/Test::Compile' version: 2.033 - class: Dist::Zilla::Plugin::Test::Perl::Critic name: '@NIGELM/Test::Perl::Critic' version: 2.112410 - class: Dist::Zilla::Plugin::MetaTests name: '@NIGELM/MetaTests' version: 4.300039 - class: Dist::Zilla::Plugin::PodSyntaxTests name: '@NIGELM/PodSyntaxTests' version: 4.300039 - class: Dist::Zilla::Plugin::Test::PodSpelling name: '@NIGELM/Test::PodSpelling' version: 2.006001 - class: Dist::Zilla::Plugin::Test::Portability name: '@NIGELM/Test::Portability' version: 2.000005 - class: Dist::Zilla::Plugin::Test::Synopsis name: '@NIGELM/Test::Synopsis' version: 2.000004 - class: Dist::Zilla::Plugin::Test::MinimumVersion name: '@NIGELM/Test::MinimumVersion' version: 2.000005 - class: Dist::Zilla::Plugin::HasVersionTests name: '@NIGELM/HasVersionTests' version: 1.101420 - class: Dist::Zilla::Plugin::Test::DistManifest name: '@NIGELM/Test::DistManifest' version: 2.000004 - class: Dist::Zilla::Plugin::Test::UnusedVars name: '@NIGELM/Test::UnusedVars' version: 2.000005 - class: Dist::Zilla::Plugin::NoTabsTests config: Dist::Zilla::Plugin::Test::NoTabs: module_finder: - ':InstallModules' script_finder: - ':ExecFiles' name: '@NIGELM/NoTabsTests' version: 0.04 - class: Dist::Zilla::Plugin::EOLTests name: '@NIGELM/EOLTests' version: 0.02 - class: Dist::Zilla::Plugin::InlineFiles name: '@NIGELM/InlineFiles' version: 4.300039 - class: Dist::Zilla::Plugin::ReportVersions name: '@NIGELM/ReportVersions' version: 1.110730 - class: Dist::Zilla::Plugin::PruneCruft name: '@NIGELM/PruneCruft' version: 4.300039 - class: Dist::Zilla::Plugin::PruneFiles name: '@NIGELM/PruneFiles' version: 4.300039 - class: Dist::Zilla::Plugin::ManifestSkip name: '@NIGELM/ManifestSkip' version: 4.300039 - class: Dist::Zilla::Plugin::AutoPrereqs name: '@NIGELM/AutoPrereqs' version: 4.300039 - class: Dist::Zilla::Plugin::MetaConfig name: '@NIGELM/MetaConfig' version: 4.300039 - class: Dist::Zilla::Plugin::MetaProvides::Class config: Dist::Zilla::Role::MetaProvider::Provider: inherit_missing: 1 inherit_version: 1 meta_noindex: 1 name: '@NIGELM/MetaProvides::Class' version: 1.14000001 - class: Dist::Zilla::Plugin::FinderCode name: '@NIGELM/MetaProvides::Package/AUTOVIV/:InstallModulesPM' version: 4.300039 - class: Dist::Zilla::Plugin::MetaProvides::Package config: Dist::Zilla::Plugin::MetaProvides::Package: {} Dist::Zilla::Role::MetaProvider::Provider: inherit_missing: 1 inherit_version: 1 meta_noindex: 1 name: '@NIGELM/MetaProvides::Package' version: 1.15000000 - class: Dist::Zilla::Plugin::MetaResources name: '@NIGELM/MetaResources' version: 4.300039 - class: Dist::Zilla::Plugin::Authority name: '@NIGELM/Authority' version: 1.006 - class: Dist::Zilla::Plugin::ExtraTests name: '@NIGELM/ExtraTests' version: 4.300039 - class: Dist::Zilla::Plugin::NextRelease name: '@NIGELM/NextRelease' version: 4.300039 - class: Dist::Zilla::Plugin::OurPkgVersion name: '@NIGELM/OurPkgVersion' version: 0.005000 - class: Dist::Zilla::Plugin::PodWeaver config: Dist::Zilla::Plugin::PodWeaver: config_plugin: '@MARCEL' finder: - ':InstallModules' - ':ExecFiles' name: '@NIGELM/PodWeaver' version: 3.102000 - class: Dist::Zilla::Plugin::License name: '@NIGELM/License' version: 4.300039 - class: Dist::Zilla::Plugin::ModuleBuild name: '@NIGELM/ModuleBuild' version: 4.300039 - class: Dist::Zilla::Plugin::MetaYAML name: '@NIGELM/MetaYAML' version: 4.300039 - class: Dist::Zilla::Plugin::MetaJSON name: '@NIGELM/MetaJSON' version: 4.300039 - class: Dist::Zilla::Plugin::ReadmeAnyFromPod name: '@NIGELM/ReadmeAnyFromPod' version: 0.131500 - class: Dist::Zilla::Plugin::ReadmeAnyFromPod name: '@NIGELM/ReadmePodInRoot' version: 0.131500 - class: Dist::Zilla::Plugin::InstallGuide name: '@NIGELM/InstallGuide' version: 1.200000 - class: Dist::Zilla::Plugin::Manifest name: '@NIGELM/Manifest' version: 4.300039 - class: Dist::Zilla::Plugin::Git::Commit name: '@NIGELM/Git::Commit' version: 2.014 - class: Dist::Zilla::Plugin::Git::Tag name: '@NIGELM/Git::Tag' version: 2.014 - class: Dist::Zilla::Plugin::Git::CommitBuild name: '@NIGELM/Git::CommitBuild' version: 2.014 - class: Dist::Zilla::Plugin::Git::Push name: '@NIGELM/Git::Push' version: 2.014 - class: Dist::Zilla::Plugin::CheckChangeLog name: '@NIGELM/CheckChangeLog' version: 0.01 - class: Dist::Zilla::Plugin::UploadToCPAN name: '@NIGELM/UploadToCPAN' version: 4.300039 - class: Dist::Zilla::Plugin::FinderCode name: ':InstallModules' version: 4.300039 - class: Dist::Zilla::Plugin::FinderCode name: ':IncModules' version: 4.300039 - class: Dist::Zilla::Plugin::FinderCode name: ':TestFiles' version: 4.300039 - class: Dist::Zilla::Plugin::FinderCode name: ':ExecFiles' version: 4.300039 - class: Dist::Zilla::Plugin::FinderCode name: ':ShareFiles' version: 4.300039 - class: Dist::Zilla::Plugin::FinderCode name: ':MainModule' version: 4.300039 zilla: class: Dist::Zilla::Dist::Builder config: is_trial: 0 version: 4.300039 x_authority: cpan:NIGELM MANIFEST100644000765000024 112712226003500 14527 0ustar00nigelstaff000000000000HTML-Scrubber-0.11Build.PL Changes INSTALL LICENSE MANIFEST META.json META.yml README lib/HTML/Scrubber.pm t/00-compile.t t/000-report-versions.t t/01_use.t t/02_basic.t t/03_more.t t/04_style_script.t t/05_pi_comment.t t/06_scrub_file.t t/07_booleans.t t/08_cb_attrs.t t/author-critic.t t/author-pod-spell.t t/release-dist-manifest.t t/release-distmeta.t t/release-eol.t t/release-has-version.t t/release-minimum-version.t t/release-no-tabs.t t/release-pod-syntax.t t/release-portability.t t/release-synopsis.t t/release-unused-vars.t t/rt19063_xhtml.t t/rt25477_self_closing.t t/rt72659_utf8.t t/rt79044_multiple.t Build.PL100644000765000024 261612226003500 14676 0ustar00nigelstaff000000000000HTML-Scrubber-0.11 use strict; use warnings; use Module::Build 0.3601; my %module_build_args = ( "build_requires" => { "Module::Build" => "0.3601" }, "configure_requires" => { "Module::Build" => "0.3601" }, "dist_abstract" => "Perl extension for scrubbing/sanitizing html", "dist_author" => [ "Ruslan Zakirov ", "Nigel Metheringham ", "D. H. " ], "dist_name" => "HTML-Scrubber", "dist_version" => "0.11", "license" => "perl", "module_name" => "HTML::Scrubber", "recommends" => {}, "recursive_test_files" => 1, "requires" => { "HTML::Entities" => 0, "HTML::Parser" => "3.47", "strict" => 0, "warnings" => 0 }, "script_files" => [], "test_requires" => { "Carp" => 0, "File::Spec" => 0, "File::Temp" => 0, "IO::Handle" => 0, "IPC::Open3" => 0, "Scalar::Util" => 0, "Test" => 0, "Test::More" => "0.94", "perl" => "5.004", "utf8" => 0 } ); unless ( eval { Module::Build->VERSION(0.4004) } ) { my $tr = delete $module_build_args{test_requires}; my $br = $module_build_args{build_requires}; for my $mod ( keys %$tr ) { if ( exists $br->{$mod} ) { $br->{$mod} = $tr->{$mod} if $tr->{$mod} > $br->{$mod}; } else { $br->{$mod} = $tr->{$mod}; } } } my $build = Module::Build->new(%module_build_args); $build->create_build_script; META.json100644000765000024 3000312226003500 15032 0ustar00nigelstaff000000000000HTML-Scrubber-0.11{ "abstract" : "Perl extension for scrubbing/sanitizing html", "author" : [ "Ruslan Zakirov ", "Nigel Metheringham ", "D. H. " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 4.300039, CPAN::Meta::Converter version 2.132661", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "HTML-Scrubber", "prereqs" : { "build" : { "requires" : { "Module::Build" : "0.3601" } }, "configure" : { "requires" : { "Module::Build" : "0.3601" } }, "develop" : { "requires" : { "Test::CPAN::Meta" : "0", "Test::More" : "0", "Test::NoTabs" : "0", "Test::Pod" : "1.41" } }, "runtime" : { "requires" : { "HTML::Entities" : "0", "HTML::Parser" : "3.47", "strict" : "0", "warnings" : "0" } }, "test" : { "requires" : { "Carp" : "0", "File::Spec" : "0", "File::Temp" : "0", "IO::Handle" : "0", "IPC::Open3" : "0", "Scalar::Util" : "0", "Test" : "0", "Test::More" : "0.94", "perl" : "5.004", "utf8" : "0" } } }, "provides" : { "HTML::Scrubber" : { "file" : "lib/HTML/Scrubber.pm", "version" : "0.11" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "mailto" : "bug-HTML-Scrubber@rt.cpan.org", "web" : "http://rt.cpan.org/Public/Dist/Display.html?Name=HTML-Scrubber" }, "homepage" : "https://metacpan.org/release/HTML-Scrubber", "repository" : { "type" : "git", "url" : "git://github.com/nigelm/html-scrubber.git", "web" : "http://github.com/nigelm/html-scrubber" } }, "version" : "0.11", "x_Dist_Zilla" : { "perl" : { "version" : "5.018001" }, "plugins" : [ { "class" : "Dist::Zilla::Plugin::Git::NextVersion", "name" : "@NIGELM/Git::NextVersion", "version" : "2.014" }, { "class" : "Dist::Zilla::Plugin::Git::Check", "name" : "@NIGELM/Git::Check", "version" : "2.014" }, { "class" : "Dist::Zilla::Plugin::GatherDir", "name" : "@NIGELM/GatherDir", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::Test::Compile", "config" : { "Dist::Zilla::Plugin::Test::Compile" : { "module_finder" : [ ":InstallModules" ], "script_finder" : [ ":ExecFiles" ] } }, "name" : "@NIGELM/Test::Compile", "version" : "2.033" }, { "class" : "Dist::Zilla::Plugin::Test::Perl::Critic", "name" : "@NIGELM/Test::Perl::Critic", "version" : "2.112410" }, { "class" : "Dist::Zilla::Plugin::MetaTests", "name" : "@NIGELM/MetaTests", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::PodSyntaxTests", "name" : "@NIGELM/PodSyntaxTests", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::Test::PodSpelling", "name" : "@NIGELM/Test::PodSpelling", "version" : "2.006001" }, { "class" : "Dist::Zilla::Plugin::Test::Portability", "name" : "@NIGELM/Test::Portability", "version" : "2.000005" }, { "class" : "Dist::Zilla::Plugin::Test::Synopsis", "name" : "@NIGELM/Test::Synopsis", "version" : "2.000004" }, { "class" : "Dist::Zilla::Plugin::Test::MinimumVersion", "name" : "@NIGELM/Test::MinimumVersion", "version" : "2.000005" }, { "class" : "Dist::Zilla::Plugin::HasVersionTests", "name" : "@NIGELM/HasVersionTests", "version" : "1.101420" }, { "class" : "Dist::Zilla::Plugin::Test::DistManifest", "name" : "@NIGELM/Test::DistManifest", "version" : "2.000004" }, { "class" : "Dist::Zilla::Plugin::Test::UnusedVars", "name" : "@NIGELM/Test::UnusedVars", "version" : "2.000005" }, { "class" : "Dist::Zilla::Plugin::NoTabsTests", "config" : { "Dist::Zilla::Plugin::Test::NoTabs" : { "module_finder" : [ ":InstallModules" ], "script_finder" : [ ":ExecFiles" ] } }, "name" : "@NIGELM/NoTabsTests", "version" : "0.04" }, { "class" : "Dist::Zilla::Plugin::EOLTests", "name" : "@NIGELM/EOLTests", "version" : "0.02" }, { "class" : "Dist::Zilla::Plugin::InlineFiles", "name" : "@NIGELM/InlineFiles", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::ReportVersions", "name" : "@NIGELM/ReportVersions", "version" : "1.110730" }, { "class" : "Dist::Zilla::Plugin::PruneCruft", "name" : "@NIGELM/PruneCruft", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::PruneFiles", "name" : "@NIGELM/PruneFiles", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::ManifestSkip", "name" : "@NIGELM/ManifestSkip", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::AutoPrereqs", "name" : "@NIGELM/AutoPrereqs", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::MetaConfig", "name" : "@NIGELM/MetaConfig", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::MetaProvides::Class", "config" : { "Dist::Zilla::Role::MetaProvider::Provider" : { "inherit_missing" : "1", "inherit_version" : "1", "meta_noindex" : "1" } }, "name" : "@NIGELM/MetaProvides::Class", "version" : "1.14000001" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : "@NIGELM/MetaProvides::Package/AUTOVIV/:InstallModulesPM", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::MetaProvides::Package", "config" : { "Dist::Zilla::Plugin::MetaProvides::Package" : {}, "Dist::Zilla::Role::MetaProvider::Provider" : { "inherit_missing" : "1", "inherit_version" : "1", "meta_noindex" : "1" } }, "name" : "@NIGELM/MetaProvides::Package", "version" : "1.15000000" }, { "class" : "Dist::Zilla::Plugin::MetaResources", "name" : "@NIGELM/MetaResources", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::Authority", "name" : "@NIGELM/Authority", "version" : "1.006" }, { "class" : "Dist::Zilla::Plugin::ExtraTests", "name" : "@NIGELM/ExtraTests", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::NextRelease", "name" : "@NIGELM/NextRelease", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::OurPkgVersion", "name" : "@NIGELM/OurPkgVersion", "version" : "0.005000" }, { "class" : "Dist::Zilla::Plugin::PodWeaver", "config" : { "Dist::Zilla::Plugin::PodWeaver" : { "config_plugin" : "@MARCEL", "finder" : [ ":InstallModules", ":ExecFiles" ] } }, "name" : "@NIGELM/PodWeaver", "version" : "3.102000" }, { "class" : "Dist::Zilla::Plugin::License", "name" : "@NIGELM/License", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::ModuleBuild", "name" : "@NIGELM/ModuleBuild", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::MetaYAML", "name" : "@NIGELM/MetaYAML", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::MetaJSON", "name" : "@NIGELM/MetaJSON", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::ReadmeAnyFromPod", "name" : "@NIGELM/ReadmeAnyFromPod", "version" : "0.131500" }, { "class" : "Dist::Zilla::Plugin::ReadmeAnyFromPod", "name" : "@NIGELM/ReadmePodInRoot", "version" : "0.131500" }, { "class" : "Dist::Zilla::Plugin::InstallGuide", "name" : "@NIGELM/InstallGuide", "version" : "1.200000" }, { "class" : "Dist::Zilla::Plugin::Manifest", "name" : "@NIGELM/Manifest", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::Git::Commit", "name" : "@NIGELM/Git::Commit", "version" : "2.014" }, { "class" : "Dist::Zilla::Plugin::Git::Tag", "name" : "@NIGELM/Git::Tag", "version" : "2.014" }, { "class" : "Dist::Zilla::Plugin::Git::CommitBuild", "name" : "@NIGELM/Git::CommitBuild", "version" : "2.014" }, { "class" : "Dist::Zilla::Plugin::Git::Push", "name" : "@NIGELM/Git::Push", "version" : "2.014" }, { "class" : "Dist::Zilla::Plugin::CheckChangeLog", "name" : "@NIGELM/CheckChangeLog", "version" : "0.01" }, { "class" : "Dist::Zilla::Plugin::UploadToCPAN", "name" : "@NIGELM/UploadToCPAN", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":InstallModules", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":IncModules", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":TestFiles", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ExecFiles", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ShareFiles", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":MainModule", "version" : "4.300039" } ], "zilla" : { "class" : "Dist::Zilla::Dist::Builder", "config" : { "is_trial" : "0" }, "version" : "4.300039" } }, "x_authority" : "cpan:NIGELM" } t000755000765000024 012226003500 13500 5ustar00nigelstaff000000000000HTML-Scrubber-0.1101_use.t100644000765000024 30312226003500 15075 0ustar00nigelstaff000000000000HTML-Scrubber-0.11/t# Check this module loads # use Test::More tests => 1; BEGIN { use_ok( 'HTML::Scrubber' ) || print "Bail out!\n"; } diag( "Testing HTML::Scrubber $HTML::Scrubber::VERSION, Perl $], $^X" ); 03_more.t100644000765000024 221412226003500 15270 0ustar00nigelstaff000000000000HTML-Scrubber-0.11/t# perl Makefile.PL && nmake realclean && cls && perl Makefile.PL && nmake test # cpan-upload -mailto yo@yo.yo -verbose -user podmaster HTML-Scrubber-0.04.tar.gz use strict; use Test::More tests => 7; BEGIN { $^W = 1 } use_ok( 'HTML::Scrubber' ); my $s = HTML::Scrubber->new; my $html = q[link
bold UNDERLINE ]; isa_ok($s, 'HTML::Scrubber'); $s->rules( 'font' => { face => 1 } ); is( $s->scrub(''), '', 'font face gothic' ); $s->allow(qw[ U ]); #use Data::Dumper;warn $/,Dumper($s); is( $s->scrub($html), q[link bold UNDERLINE ],'only U'); $s->allow(qw[ B U ]); #use Data::Dumper;warn $/,Dumper($s); is( $s->scrub($html), q[link bold UNDERLINE ],'B and U'); $s->allow(qw[ A B ]); $s->deny('U'); $s->default(0,{ '*'=> 1}); #use Data::Dumper;warn $/,Dumper($s); is( $s->scrub($html), q[link bold UNDERLINE ],'A and B'); $s = HTML::Scrubber->new( default => [ 1, { '*' => 1 } ] ); is( $s->scrub($html), q[link
bold UNDERLINE ], 'A B U and BR'); #use Data::Dumper;warn $/,Dumper($s); 02_basic.t100644000765000024 1355612226003500 15441 0ustar00nigelstaff000000000000HTML-Scrubber-0.11/t# Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl test.pl' ######################### # change 'tests => 1' to 'tests => last_test_to_print'; use Test; BEGIN { plan tests => 77 } use HTML::Scrubber; ok(1); # If we made it this far, we're ok. # test 1 ######################### # Insert your test code below, the Test module is use()ed here so read # its man page ( perldoc Test ) for help writing this test script. my $html = q[
bold < underlined LINK ]; my $scrubber = HTML::Scrubber->new(); ok($scrubber); # test 2 ok( !$scrubber->default() ); # test 3 ok( !$scrubber->comment() ); # test 4 ok( !$scrubber->process() ); # test 5 ok( !$scrubber->allow(qw[ p b i u hr br ]) ); # test 6 $scrubber = $scrubber->scrub($html); ok($scrubber); # test 7 ok( $scrubber !~ /href/i ); # test 8 ok( $scrubber !~ /Align/i ); # test 9 ok( $scrubber !~ /\Q mid1 mid2 end]; isa_ok($s, 'HTML::Scrubber'); is( $s->comment, 0, 'comment off by default'); is( $s->process, 0, 'process off by default'); is( $s->scrub($html), 'start mid1 mid2 end'); $s->comment(1); is( $s->comment, 1, 'comment on'); is( $s->scrub($html), 'start mid1 mid2 end', 'comment on'); $s->process(1); is( $s->process, 1, 'process on'); is( $s->scrub($html), 'start mid1 mid2 end', 'process on');06_scrub_file.t100644000765000024 342512226003500 16453 0ustar00nigelstaff000000000000HTML-Scrubber-0.11/t# perl Makefile.PL && nmake realclean && cls && perl Makefile.PL && nmake test use strict; use File::Temp qw/ tempfile tempdir /; use Test::More tests => 10; BEGIN { $^W = 1 } use_ok('HTML::Scrubber'); my $s = HTML::Scrubber->new; my $html = q[

hi
start mid1 mid2 end]; isa_ok( $s, 'HTML::Scrubber' ); my $tmpdir = tempdir( CLEANUP => 1 ); SKIP: { skip "no writable temporary directory found", 6 unless length $tmpdir and -d $tmpdir; my $template = 'html-scrubber-XXXX'; my ( $tfh, $tmpfile ) = tempfile( $template, DIR => $tmpdir, SUFFIX => '.html' ); my $r = $s->scrub( $html, $tmpfile ); $r = "Error: \$@=$@ \$!=$!" unless $r; is( $r, 1, "scrub(\$html,\$tmpfile=$tmpfile)" ); local *FILIS; open FILIS, "+>$tmpfile" or die "can't write to $tmpfile"; $r = $s->scrub( $html, \*FILIS ); $r = "Error: \$@=$@ \$!=$!" unless $r; is( $r, 1, q[scrub($html,\*FILIS)] ); seek *FILIS, 0, 0; $r = join '', readline *FILIS; is( $r, "histart mid1 mid2 end", "FILIS has the right stuff" ); is( close(FILIS), 1, q[close(FILIS)] ); my ( $tfh2, $tmpfile2 ) = tempfile( $template, DIR => $tmpdir, SUFFIX => '.html' ); $r = $s->scrub_file( $tmpfile, "$tmpfile2" ); $r = "Error: \$@=$@ \$!=$!" unless $r; is( $r, 1, qq[scrub_file(\$tmpfile,"\$tmpfile2"=$tmpfile2)] ); open FILIS, "+>$tmpfile2" or die "can't write to $tmpfile"; $r = $s->scrub_file( $tmpfile, \*FILIS ); $r = "Error: \$@=$@ \$!=$!" unless $r; is( $r, 1, q[scrub_file($tmpfile,\*FILIS)] ); seek *FILIS, 0, 0; $r = join '', readline *FILIS; is( $r, "histart mid1 mid2 end", "FILIS has the right stuff" ); is( close(FILIS), 1, q[close(FILIS)] ); } rt19063_xhtml.t100644000765000024 56512226003500 16257 0ustar00nigelstaff000000000000HTML-Scrubber-0.11/t# Tests related to RT25477 - https://rt.cpan.org/Public/Bug/Display.html?id=25477 use strict; use warnings; use File::Spec; use Test::More; use_ok('HTML::Scrubber'); use HTML::Scrubber; my $scrubber = HTML::Scrubber->new; $scrubber->default(1); is( $scrubber->scrub('





'), '



', "correct result" ); done_testing; author-critic.t100644000765000024 66612226003500 16572 0ustar00nigelstaff000000000000HTML-Scrubber-0.11/t#!perl BEGIN { unless ($ENV{AUTHOR_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for testing by the author'); } } use strict; use warnings; use Test::More; use English qw(-no_match_vars); eval "use Test::Perl::Critic"; plan skip_all => 'Test::Perl::Critic required to criticise code' if $@; Test::Perl::Critic->import( -profile => "perlcritic.rc" ) if -e "perlcritic.rc"; all_critic_ok(); 04_style_script.t100644000765000024 135712226003500 17062 0ustar00nigelstaff000000000000HTML-Scrubber-0.11/t# perl Makefile.PL && nmake realclean && cls && perl Makefile.PL && nmake test use strict; use Test::More tests => 9; BEGIN { $^W = 1 } use_ok( 'HTML::Scrubber' ); my $s = HTML::Scrubber->new; my $html = q[start middle end]; isa_ok($s, 'HTML::Scrubber'); is( $s->script, 0, 'script off by default'); is( $s->style, 0, 'style off by default'); is( $s->scrub($html), 'start middle end', 'default (no style no script)'); $s->script(1); is( $s->script, 1, 'script on'); is( $s->scrub($html), 'start middle in the script end', 'script off'); $s->style(1); is( $s->style, 1, 'style on'); is( $s->scrub($html), 'start in the style middle in the script end', 'style off and script off');release-no-tabs.t100644000765000024 60012226003500 16762 0ustar00nigelstaff000000000000HTML-Scrubber-0.11/t BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } use strict; use warnings; # this test was generated with Dist::Zilla::Plugin::NoTabsTests 0.04 use Test::More 0.88; use Test::NoTabs; my @files = ( 'lib/HTML/Scrubber.pm' ); notabs_ok($_) foreach @files; done_testing; HTML000755000765000024 012226003500 14547 5ustar00nigelstaff000000000000HTML-Scrubber-0.11/libScrubber.pm100644000765000024 4370112226003500 17041 0ustar00nigelstaff000000000000HTML-Scrubber-0.11/lib/HTMLpackage HTML::Scrubber; # ABSTRACT: Perl extension for scrubbing/sanitizing html use strict; use warnings; use HTML::Parser 3.47 (); use HTML::Entities; our( @_scrub, @_scrub_fh ); our $VERSION = '0.11'; # VERSION our $AUTHORITY = 'cpan:NIGELM'; # AUTHORITY # my my my my, these here to prevent foolishness like # http://perlmonks.org/index.pl?node_id=251127#Stealing+Lexicals (@_scrub )= ( \&_scrub, "self, event, tagname, attr, attrseq, text"); (@_scrub_fh )= ( \&_scrub_fh, "self, event, tagname, attr, attrseq, text"); sub new { my $package = shift; my $p = HTML::Parser->new( api_version => 3, default_h => \@_scrub, marked_sections => 0, strict_comment => 0, unbroken_text => 1, case_sensitive => 0, boolean_attribute_value => undef, empty_element_tags => 1, ); my $self = { _p => $p, _rules => { '*' => 0, }, _comment => 0, _process => 0, _r => "", _optimize => 1, _script => 0, _style => 0, }; $p->{"\0_s"} = bless $self, $package; return $self unless @_; my(%args)= @_; for my $f( qw[ default allow deny rules process comment ] ) { next unless exists $args{$f}; if( ref $args{$f} ) { $self->$f( @{ $args{$f} } ) ; } else { $self->$f( $args{$f} ) ; } } return $self; } sub comment { return $_[0]->{_comment} if @_ == 1; $_[0]->{_comment} = $_[1]; return; } sub process { return $_[0]->{_process} if @_ == 1; $_[0]->{_process} = $_[1]; return; } sub script { return $_[0]->{_script} if @_ == 1; $_[0]->{_script} = $_[1]; return; } sub style { return $_[0]->{_style} if @_ == 1; $_[0]->{_style} = $_[1]; return; } sub allow { my $self = shift; for my $k(@_){ $self->{_rules}{lc $k}=1; } $self->{_optimize} = 1; # each time a rule changes, reoptimize when parse return; } sub deny { my $self = shift; for my $k(@_){ $self->{_rules}{lc $k} = 0; } $self->{_optimize} = 1; # each time a rule changes, reoptimize when parse return; } sub rules{ my $self = shift; my(%rules)= @_; for my $k(keys %rules) { $self->{_rules}{lc $k} = $rules{$k}; } $self->{_optimize} = 1; # each time a rule changes, reoptimize when parse return; } sub default { return $_[0]->{_rules}{'*'} if @_ == 1; $_[0]->{_rules}{'*'} = $_[1] if defined $_[1]; $_[0]->{_rules}{'_'} = $_[2] if defined $_[2] and ref $_[2]; $_[0]->{_optimize} = 1; # each time a rule changes, reoptimize when parse return; } sub scrub_file { if(@_ > 2){ return unless defined $_[0]->_out($_[2]); } else { $_[0]->{_p}->handler( default => @_scrub ); } $_[0]->_optimize() ;#if $_[0]->{_optimize}; $_[0]->{_p}->parse_file($_[1]); return delete $_[0]->{_r} unless exists $_[0]->{_out}; print { $_[0]->{_out} } $_[0]->{_r} if length $_[0]->{_r}; delete $_[0]->{_out}; return 1; } sub scrub { if(@_ > 2){ return unless defined $_[0]->_out($_[2]); } else { $_[0]->{_p}->handler( default => @_scrub ); } $_[0]->_optimize();# if $_[0]->{_optimize}; $_[0]->{_p}->parse($_[1]); $_[0]->{_p}->eof(); return delete $_[0]->{_r} unless exists $_[0]->{_out}; delete $_[0]->{_out}; return 1; } sub _out { my($self, $o ) = @_; unless( ref $o and ref \$o ne 'GLOB') { open my $F, '>', $o or return; binmode $F; $self->{_out} = $F; } else { $self->{_out} = $o; } $self->{_p}->handler( default => @_scrub_fh ); return 1; } sub _validate { my($s, $t, $r, $a, $as) = @_; return "<$t>" unless %$a; $r = $s->{_rules}->{$r}; my %f; for my $k( keys %$a ) { my $check = exists $r->{$k}? $r->{$k} : exists $r->{'*'}? $r->{'*'} : next; if( ref $check eq 'CODE' ) { my @v = $check->( $s, $t, $k, $a->{$k}, $a, \%f ); next unless @v; $f{$k} = shift @v; } elsif( ref $check || length($check) > 1 ) { $f{$k} = $a->{$k} if $a->{$k} =~ m{$check}; } elsif( $check ) { $f{$k} = $a->{$k}; } } if( %f ){ my %seen; return "<$t $r>" if $r = join ' ', map { defined $f{$_} ? qq[$_="].encode_entities($f{$_}).q["] : $_; # boolean attribute (TODO?) } grep { exists $f{$_} and !$seen{$_}++; } @$as; } return "<$t>"; } sub _scrub_str { my ( $p, $e, $t, $a, $as, $text ) = @_; my $s = $p->{"\0_s"}; my $outstr = ''; if ( $e eq 'start' ) { if ( exists $s->{_rules}->{$t} ) # is there a specific rule { if ( ref $s->{_rules}->{$t} ) # is it complicated?(not simple;) { $outstr .= $s->_validate( $t, $t, $a, $as ); } elsif ( $s->{_rules}->{$t} ) # validate using default attribute rule { $outstr .= $s->_validate( $t, '_', $a, $as ); } } elsif ( $s->{_rules}->{'*'} ) # default allow tags { $outstr .= $s->_validate( $t, '_', $a, $as ); } } elsif ( $e eq 'end' ) { my $place = 0; if ( exists $s->{_rules}->{$t} ) { $place = 1 if $s->{_rules}->{$t}; } elsif ( $s->{_rules}->{'*'} ) { $place = 1; } if ( $place ) { if ( length $text ) { $outstr .= ""; } else { substr $s->{_r}, -1, 0, ' /'; } } } elsif ( $e eq 'comment' ) { $outstr .= $text if $s->{_comment}; } elsif ( $e eq 'process' ) { $outstr .= $text if $s->{_process}; } elsif ( $e eq 'text' or $e eq 'default' ) { $text =~ s//>/g; $outstr .= $text; } elsif ( $e eq 'start_document' ) { $outstr = ""; } return $outstr; } sub _scrub_fh { my $self = $_[0]->{"\0_s"}; print { $self->{_out} } $self->{'_r'} if length $self->{_r}; $self->{'_r'} = _scrub_str(@_); } sub _scrub { $_[0]->{"\0_s"}->{_r} .= _scrub_str(@_); } sub _optimize { my($self) = @_; my( @ignore_elements ) = grep { not $self->{"_$_"} } qw(script style); $self->{_p}->ignore_elements(@ignore_elements); # if @ is empty, we reset ;) return unless $self->{_optimize}; #sub allow # return unless $self->{_optimize}; # till I figure it out (huh) if( $self->{_rules}{'*'} ){ # default allow $self->{_p}->report_tags(); # so clear it } else { my(@reports) = grep { # report only tags we want $self->{_rules}{$_} } keys %{ $self->{_rules} }; $self->{_p}->report_tags( # default deny, so optimize @reports ) if @reports; } # sub deny # return unless $self->{_optimize}; # till I figure it out (huh) my(@ignores)= grep { not $self->{_rules}{$_} } grep { $_ ne '*' } keys %{ $self->{_rules} }; $self->{_p}->ignore_tags( # always ignore stuff we don't want @ignores ) if @ignores; $self->{_optimize}=0; return; } sub DESTROY { delete $_[0]->{_p}->{"\0_s"}; # break circular reference } 1; #print sprintf q[ '%-12s => %s,], "$_'", $h{$_} for sort keys %h;# perl! #perl -ne"chomp;print $_;print qq'\t\t# test ', ++$a if /ok\(/;print $/" test.pl >test2.pl #perl -ne"chomp;print $_;if( /ok\(/ ){s/\#test \d+$//;print qq'\t\t# test ', ++$a }print $/" test.pl >test2.pl #perl -ne"chomp;if(/ok\(/){s/# test .*$//;print$_,qq'\t\t# test ',++$a}else{print$_}print$/" test.pl >test2.pl __END__ =pod =for stopwords html cpan callback homepage =head1 NAME HTML::Scrubber - Perl extension for scrubbing/sanitizing html =head1 VERSION version 0.11 =head1 SYNOPSIS use HTML::Scrubber; my $scrubber = HTML::Scrubber->new( allow => [ qw[ p b i u hr br ] ] ); print $scrubber->scrub('

bold missing

'); # output is:

bold

# more complex input my $html = q[
a => link br =>
b => bold u => UNDERLINE ]; print $scrubber->scrub($html); $scrubber->deny( qw[ p b i u hr br ] ); print $scrubber->scrub($html); =head1 DESCRIPTION If you want to "scrub" or "sanitize" html input in a reliable and flexible fashion, then this module is for you. I wasn't satisfied with HTML::Sanitizer because it is based on HTML::TreeBuilder, so I thought I'd write something similar that works directly with HTML::Parser. =head1 METHODS First a note on documentation: just study the L below. It's all the documentation you could need Also, be sure to read all the comments as well as L. If you're new to perl, good luck to you. =head2 comment warn "comments are ", $p->comment ? 'allowed' : 'not allowed'; $p->comment(0); # off by default =head2 process warn "process instructions are ", $p->process ? 'allowed' : 'not allowed'; $p->process(0); # off by default =head2 script warn "script tags (and everything in between) are supressed" if $p->script; # off by default $p->script( 0 || 1 ); B<**> Please note that this is implemented using HTML::Parser's ignore_elements function, so if C two END is($scrubbed, <<'END', "correct result"); one two END done_testing; release-dist-manifest.t100644000765000024 46612226003500 20200 0ustar00nigelstaff000000000000HTML-Scrubber-0.11/t#!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } use Test::More; eval "use Test::DistManifest"; plan skip_all => "Test::DistManifest required for testing the manifest" if $@; manifest_ok(); release-minimum-version.t100644000765000024 52612226003500 20564 0ustar00nigelstaff000000000000HTML-Scrubber-0.11/t#!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } use Test::More; eval "use Test::MinimumVersion"; plan skip_all => "Test::MinimumVersion required for testing minimum versions" if $@; all_minimum_version_from_metayml_ok();