Skip to content

Commit

Permalink
escape apostrophe/single quote
Browse files Browse the repository at this point in the history
closes mlawren#1
  • Loading branch information
joenio committed Nov 29, 2015
1 parent 069eeb0 commit 639925f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/XML/API.pm
Expand Up @@ -891,12 +891,13 @@ sub _fast_string {
sub _escapeXML {
my $data = $_[0];
return '' unless(defined($data));
if ($data =~ /[\&\<\>\"(__AMP__)]/o) {
if ($data =~ /[\&\<\>\"(__AMP__)\']/o) {
$data =~ s/\&(?!\w+\;)/\&amp\;/go;
$data =~ s/\</\&lt\;/go;
$data =~ s/\>/\&gt\;/go;
$data =~ s/\"/\&quot\;/go;
$data =~ s/__AMP__/\&/go;
$data =~ s/\'/\&apos\;/go;
}
return $data;
}
Expand Down
8 changes: 6 additions & 2 deletions t/04-parse.t
@@ -1,6 +1,6 @@
use strict;
use warnings;
use Test::More tests => 9;
use Test::More tests => 10;
use Test::Exception;
use Test::Memory::Cycle;

Expand Down Expand Up @@ -63,4 +63,8 @@ is("$x", '<?xml version="1.0" encoding="UTF-8" ?>

memory_cycle_ok($x, 'memory cycle');


is(XML::API::_escapeXML(
" ' "
),
" &apos; ",
'escape apostrophe/single quote');

0 comments on commit 639925f

Please sign in to comment.