| 1 | package HTML::Widget::Filter::HTMLEscape; | ||
| 2 | |||
| 3 | use warnings; | ||
| 4 | use strict; | ||
| 5 | use base 'HTML::Widget::Filter'; | ||
| 6 | |||
| 7 | =head1 NAME | ||
| 8 | |||
| 9 | HTML::Widget::Filter::HTMLEscape - HTML Escaping Filter | ||
| 10 | |||
| 11 | =head1 SYNOPSIS | ||
| 12 | |||
| 13 | my $f = $widget->filter( 'HTMLEscape', 'foo' ); | ||
| 14 | |||
| 15 | =head1 DESCRIPTION | ||
| 16 | |||
| 17 | HTML Escaping Filter. | ||
| 18 | |||
| 19 | =head1 METHODS | ||
| 20 | |||
| 21 | =head2 filter | ||
| 22 | |||
| 23 | =cut | ||
| 24 | |||
| 25 | sub filter { | ||
| 26 | my ( $self, $value ) = @_; | ||
| 27 | return unless defined $value; | ||
| 28 | $value =~ s/&(?!(amp|lt|gt|quot);)/&/g; | ||
| 29 | $value =~ s/</</g; | ||
| 30 | $value =~ s/>/>/g; | ||
| 31 | $value =~ s/\"/"/g; | ||
| 32 | return $value; | ||
| 33 | } | ||
| 34 | |||
| 35 | =head1 BUGS | ||
| 36 | |||
| 37 | L<HTML::Element> now checks for, and refuses to escape already-escaped | ||
| 38 | characters. This means that if you wish to double-escape characters, you must | ||
| 39 | now do it yourself. | ||
| 40 | |||
| 41 | =head1 AUTHOR | ||
| 42 | |||
| 43 | Lyo Kato, C<lyo.kato@gmail.com> | ||
| 44 | |||
| 45 | =head1 LICENSE | ||
| 46 | |||
| 47 | This library is free software, you can redistribute it and/or modify it under | ||
| 48 | the same terms as Perl itself. | ||
| 49 | |||
| 50 | =cut | ||
| 51 | |||
| 52 | 1; |