summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorjeff <jeff>2010-09-16 04:22:05 +0000
committerjeff <jeff>2010-09-16 04:22:05 +0000
commit62b6bbdbc1f67ef71aac658cd8ff535022d3df11 (patch)
treea87680254ba938c615fd0bef530bf2db2cfa9b8c /lib
parentd1336f14bcb3ab82414b2ca25f802904c0f28a96 (diff)
escape the XML special characters
Diffstat (limited to 'lib')
-rw-r--r--lib/Net/OpenSRS.pm23
1 files changed, 21 insertions, 2 deletions
diff --git a/lib/Net/OpenSRS.pm b/lib/Net/OpenSRS.pm
index 07f2e3e..34303ab 100644
--- a/lib/Net/OpenSRS.pm
+++ b/lib/Net/OpenSRS.pm
@@ -150,7 +150,7 @@ use XML::Simple;
use Digest::MD5;
use Date::Calc qw/ Add_Delta_Days Today This_Year /;
-our $VERSION = '0.05';
+our $VERSION = '0.06';
my $rv;
*hash = \&Digest::MD5::md5_hex;
@@ -1194,6 +1194,24 @@ XML
return $self->last_response(1);
}
+# encode special characters
+
+my %encode_hash = (
+ '<' => '&lt;',
+ '>' => '&gt;',
+ "'" => '&apos;',
+ '"' => '&quot;',
+ '&' => '&amp;',
+);
+
+sub _encode
+{
+ my $arg = shift;
+ return $arg unless ($arg =~/\<|\>|\'|\"|\&/);
+ $arg =~ s/(\<|\>|\'|\"|\&)/$encode_hash{$1}/ge;
+ $arg
+}
+
# format perl structs into opensrs XML
sub _format
{
@@ -1207,7 +1225,7 @@ sub _format
my $c = 0;
$xml .= "$sp<item key=\"$_\">\n";
$xml .= "$sp <dt_array>\n";
- foreach (sort @$val) {
+ foreach (map { _encode($_) } sort @$val) {
$xml .= "$sp <item key=\"$c\">$_</item>\n";
$c++;
}
@@ -1226,6 +1244,7 @@ sub _format
}
else {
+ $val = _encode($val);
$xml .= "$sp<item key=\"$_\">$val</item>\n";
}