Skip to content

Commit

Permalink
Bumps version to 2.1.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
oalders committed Mar 3, 2013
1 parent 824d396 commit 7f53c4f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 35 deletions.
3 changes: 3 additions & 0 deletions 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.
Expand Down
1 change: 0 additions & 1 deletion MANIFEST.SKIP
@@ -1,3 +1,2 @@
.gitignore
MANIFEST.SKIP
html-restrict.komodoproject
61 changes: 31 additions & 30 deletions README
Expand Up @@ -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;
Expand All @@ -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.

Expand Down Expand Up @@ -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:

Expand Down Expand Up @@ -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]"

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion dist.ini
Expand Up @@ -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]
Expand Down
6 changes: 3 additions & 3 deletions lib/HTML/Restrict.pm
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 7f53c4f

Please sign in to comment.