Extend WebGUI::HTML::filter to also do encode XML entities.

This commit is contained in:
Colin Kuskie 2009-08-05 21:47:14 +00:00
parent 610e9b9e67
commit 55e0feb687
2 changed files with 18 additions and 1 deletions

View file

@ -19,6 +19,7 @@ use HTML::TagFilter;
use strict; use strict;
use WebGUI::Macro; use WebGUI::Macro;
use HTML::Parser; use HTML::Parser;
use HTML::Entities;
=head1 NAME =head1 NAME
@ -96,7 +97,9 @@ The HTML content you want filtered.
=head3 filter =head3 filter
Choose from "all", "none", "macros", "javascript", or "most". Defaults to "most". "all" removes all HTML tags and macros; "none" removes no HTML tags; "javascript" removes all references to javacript and macros; "macros" removes all macros, but nothing else; and "most" removes all but simple formatting tags like bold and italics. Choose from "all", "none", "macros", "javascript", "xml", or "most". Defaults to "most". "all" removes all HTML tags and macros; "none" removes no HTML tags; "javascript" removes all references to javacript and macros; "macros" removes all macros, but nothing else; and "most" removes all but simple formatting tags like bold and italics.
"xml" will enocde XML entities.
=cut =cut
@ -160,6 +163,8 @@ sub filter {
WebGUI::Macro::negate(\$html); WebGUI::Macro::negate(\$html);
} elsif ($type eq "macros") { } elsif ($type eq "macros") {
WebGUI::Macro::negate(\$html); WebGUI::Macro::negate(\$html);
} elsif ($type eq "xml") {
return HTML::Entities::encode_numeric($html)
} elsif ($type eq "none") { } elsif ($type eq "none") {
# do nothing # do nothing
} else { } else {

View file

@ -81,6 +81,18 @@ my @filterSets = (
type => 'all', type => 'all',
comment => 'all, specific iframe test case', comment => 'all, specific iframe test case',
}, },
{
inputText => q! !,
output => q! !,
type => 'xml',
comment => 'xml,  ',
},
{
inputText => q!> < "!,
output => q!&#x3E; &#x3C; &#x22;!,
type => 'xml',
comment => 'xml, other characters',
},
); );
my @macroParamSets = ( my @macroParamSets = (