Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Bumps version to 2.1.0.

  • Loading branch information...
commit 7f53c4ff0c5f401ec3e4f3067812bdb154ea1d50 1 parent 824d396
@oalders authored
View
3  Changes
@@ -1,5 +1,8 @@
Revision history for HTML-Restrict
+2.1.0 2013-03-02
+ - Allows attributes to be validated against regexes (perlpong).
+
2.0.0 2013-02-27
- Bumps version to 2.0.0 due to new features breaking backwards
compatibility.
View
1  MANIFEST.SKIP
@@ -1,3 +1,2 @@
.gitignore
MANIFEST.SKIP
-html-restrict.komodoproject
View
61 README
@@ -2,7 +2,7 @@ NAME
HTML::Restrict - Strip unwanted HTML tags and attributes
VERSION
- version 2.0.0
+ version 2.1.0
SYNOPSIS
use HTML::Restrict;
@@ -28,29 +28,8 @@ SYNOPSIS
# $processed now equals: <b>hello</b> <img src="pic.jpg" alt="me" />
- # you can also specify a regex to be tested against the attribute value
- my $hr = HTML::Restrict->new(
- rules => {
- iframe => [
- qw( width height allowfullscreen ),
- { src => qr{^http://www\.youtube\.com},
- frameborder => qr{^(0|1)$},
- }
- ],
- img => [
- qw( alt ),
- { src => qr{^/my/images/} },
- ],
- },
- );
-
- my $html = '<img src="http://www.example.com/image.jpg" alt="Alt Text">';
- my $processed = $hr->process( $html );
-
- # $processed now equals: <img alt="Alt Text">
-
DESCRIPTION
- This module uses *HTML::Parser* to strip HTML from text in a restrictive
+ This module uses HTML::Parser to strip HTML from text in a restrictive
manner. By default all HTML is restricted. You may alter the default
behaviour by supplying your own tag rules.
@@ -120,7 +99,7 @@ CONSTRUCTOR AND STARTUP
);
my $hr = HTML::Restrict->new( rules => \%rules );
- Since *HTML::Parser* treats a closing slash as an attribute, you'll
+ Since HTML::Parser treats a closing slash as an attribute, you'll
need to add "/" to your list of allowed attributes if you'd like
your tags to retain closing slashes. For example:
@@ -152,14 +131,26 @@ CONSTRUCTOR AND STARTUP
this, but you should be aware that your elements are being
reconstructed rather than just stripped down.
- Also note that all tag and attribute names must be supplied in lower
- case.
+ As of 2.1.0, you can also specify a regex to be tested against the
+ attribute value. This feature should be considered experimental for
+ the time being:
- # correct
- my $hr = HTML::Restrict->new( rules => { body => ['onload'] } );
+ my $hr = HTML::Restrict->new(
+ rules => {
+ iframe => [
+ qw( width height allowfullscreen ),
+ { src => qr{^http://www\.youtube\.com},
+ frameborder => qr{^(0|1)$},
+ }
+ ],
+ img => [ qw( alt ), { src => qr{^/my/images/} }, ],
+ },
+ );
- # throws a fatal error
- my $hr = HTML::Restrict->new( rules => { Body => ['onLoad'] } );
+ my $html = '<img src="http://www.example.com/image.jpg" alt="Alt Text">';
+ my $processed = $hr->process( $html );
+
+ # $processed now equals: <img alt="Alt Text">
* "trim => [0|1]"
@@ -261,6 +252,16 @@ SUBROUTINES/METHODS
removes any tags and attributes which are not specifically allowed and
returns the resulting text. Requires and returns a SCALAR.
+CAVEATS
+ Please note that all tag and attribute names passed via the rules param
+ must be supplied in lower case.
+
+ # correct
+ my $hr = HTML::Restrict->new( rules => { body => ['onload'] } );
+
+ # throws a fatal error
+ my $hr = HTML::Restrict->new( rules => { Body => ['onLoad'] } );
+
MOTIVATION
There are already several modules on the CPAN which accomplish much of
the same thing, but after doing a lot of poking around, I was unable to
View
2  dist.ini
@@ -3,7 +3,7 @@ author = Olaf Alders <olaf@wundercounter.com>
license = Perl_5
copyright_holder = Olaf Alders
copyright_year = 2013
-version = 2.0.0
+version = 2.1.0
main_module = lib/HTML/Restrict.pm
[GatherDir]
View
6 lib/HTML/Restrict.pm
@@ -303,7 +303,7 @@ sub _delete_tag_from_stack {
=head1 DESCRIPTION
-This module uses I<HTML::Parser> to strip HTML from text in a restrictive
+This module uses L<HTML::Parser> to strip HTML from text in a restrictive
manner. By default all HTML is restricted. You may alter the default
behaviour by supplying your own tag rules.
@@ -402,7 +402,7 @@ Allow bolded text, images and some (but not all) image attributes:
);
my $hr = HTML::Restrict->new( rules => \%rules );
-Since I<HTML::Parser> treats a closing slash as an attribute, you'll need to
+Since L<HTML::Parser> treats a closing slash as an attribute, you'll need to
add "/" to your list of allowed attributes if you'd like your tags to retain
closing slashes. For example:
@@ -433,7 +433,7 @@ element order you don't need to pay any attention to this, but you should be
aware that your elements are being reconstructed rather than just stripped
down.
-As of 2.0.1, you can also specify a regex to be tested against the attribute
+As of 2.1.0, you can also specify a regex to be tested against the attribute
value. This feature should be considered experimental for the time being:
my $hr = HTML::Restrict->new(
Please sign in to comment.
Something went wrong with that request. Please try again.