| Template-Stash-EscapeHTML documentation | Contained in the Template-Stash-EscapeHTML distribution. |
Template::Stash::EscapeHTML - escape HTML automatically in Template-Toolkit.
use Template::Stash::EscapeHTML;
my $tt = Template->new({
STASH => Template::Stash::EscapeHTML->new,
...
});
This module is a sub class of Template::Stash, automatically escape all HTML strings and avoid XSS vulnerability.
Tomohiro IKEBE, <ikebe@shebang.jp>
Copyright 2005 Tomohiro IKEBE, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| Template-Stash-EscapeHTML documentation | Contained in the Template-Stash-EscapeHTML distribution. |
package Template::Stash::EscapeHTML; use strict; use Template::Config; use base ($Template::Config::STASH); our $VERSION = '0.02'; sub get { my($self, @args) = @_; my($var) = $self->SUPER::get(@args); unless (ref($var)) { return html_filter($var); } return $var; } sub html_filter { my $text = shift; for ($text) { s/&/&/g; s/</</g; s/>/>/g; s/"/"/g; s/'/'/g; } return $text; } 1; __END__