summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/TUWF/XML.pm10
-rw-r--r--lib/TUWF/XML.pod4
2 files changed, 6 insertions, 8 deletions
diff --git a/lib/TUWF/XML.pm b/lib/TUWF/XML.pm
index a64dd46..86d05b1 100644
--- a/lib/TUWF/XML.pm
+++ b/lib/TUWF/XML.pm
@@ -117,17 +117,15 @@ sub mkclass {
# XML escape (not a method)
+my %XML = qw/& &amp; < &lt; " &quot;/;
sub xml_escape {
- local $_ = shift;
+ local $_ = $_[0];
if(!defined $_) {
carp "Attempting to XML-escape an undefined value";
return '';
}
- s/&/&amp;/g;
- s/</&lt;/g;
- s/>/&gt;/g;
- s/"/&quot;/g;
- return $_;
+ s/([&<"])/$XML{$1}/g;
+ $_;
}
# HTML escape, also does \n to <br /> conversion
diff --git a/lib/TUWF/XML.pod b/lib/TUWF/XML.pod
index 2973a15..7a0e529 100644
--- a/lib/TUWF/XML.pod
+++ b/lib/TUWF/XML.pod
@@ -130,8 +130,8 @@ Note that the order in which classes are returned may be somewhat random.
=head2 xml_escape(string)
-Returns the XML-escaped string. The characters C<&>, C<E<lt>>, C<E<gt>> and
-C<"> will be replaced with their XML entity.
+Returns the XML-escaped string. The characters C<&>, C<E<lt>>, and C<"> will be
+replaced with their XML entity.
=head2 html_escape(string)