From 55e0feb687bdf7dd844c4888b811a051a83136b7 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Wed, 5 Aug 2009 21:47:14 +0000 Subject: [PATCH] Extend WebGUI::HTML::filter to also do encode XML entities. --- lib/WebGUI/HTML.pm | 7 ++++++- t/HTML.t | 12 ++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/WebGUI/HTML.pm b/lib/WebGUI/HTML.pm index 7010771da..2e9c80f1d 100644 --- a/lib/WebGUI/HTML.pm +++ b/lib/WebGUI/HTML.pm @@ -19,6 +19,7 @@ use HTML::TagFilter; use strict; use WebGUI::Macro; use HTML::Parser; +use HTML::Entities; =head1 NAME @@ -96,7 +97,9 @@ The HTML content you want filtered. =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 @@ -160,6 +163,8 @@ sub filter { WebGUI::Macro::negate(\$html); } elsif ($type eq "macros") { WebGUI::Macro::negate(\$html); + } elsif ($type eq "xml") { + return HTML::Entities::encode_numeric($html) } elsif ($type eq "none") { # do nothing } else { diff --git a/t/HTML.t b/t/HTML.t index fbdb151f9..66800b9ba 100644 --- a/t/HTML.t +++ b/t/HTML.t @@ -81,6 +81,18 @@ my @filterSets = ( type => 'all', comment => 'all, specific iframe test case', }, + { + inputText => q! !, + output => q!&nbsp;!, + type => 'xml', + comment => 'xml,  ', + }, + { + inputText => q!> < "!, + output => q!> < "!, + type => 'xml', + comment => 'xml, other characters', + }, ); my @macroParamSets = (