| 1 |
|
| 2 |
# This is a bug fix for: |
| 3 |
# https://rt.cpan.org/Ticket/Display.html?id=70321 |
| 4 |
# |
| 5 |
# When the match callback returns 1 and the open callback returns undef, then the |
| 6 |
# read callback (inside the XS code) warnings about: |
| 7 |
# "Use of uninitialized value in subroutine entry at". |
| 8 |
# |
| 9 |
# This is due to the value returned being undef and processed by SvPV. |
| 10 |
|
| 11 |
use strict; |
| 12 |
use warnings; |
| 13 |
|
| 14 |
use lib './t/lib'; |
| 15 |
|
| 16 |
use Test::More; |
| 17 |
use File::Spec; |
| 18 |
|
| 19 |
BEGIN |
| 20 |
{ |
| 21 |
# Part of the fix for https://rt.cpan.org/Ticket/Display.html?id=86665 |
| 22 |
delete $ENV{'XML_CATALOG_FILES'}; |
| 23 |
} |
| 24 |
|
| 25 |
use XML::LibXML; |
| 26 |
|
| 27 |
if (! eval { require URI::file; } ) |
| 28 |
{ |
| 29 |
plan skip_all => "URI::file is not available."; |
| 30 |
} |
| 31 |
elsif ( URI->VERSION() < 1.35 ) |
| 32 |
{ |
| 33 |
plan skip_all => "URI >= 1.35 is not available (".URI->VERSION.")."; |
| 34 |
} |
| 35 |
else |
| 36 |
{ |
| 37 |
plan tests => 1; |
| 38 |
} |
| 39 |
|
| 40 |
sub _escape_html |
| 41 |
{ |
| 42 |
my $string = shift; |
| 43 |
$string =~ s{&}{&}gso; |
| 44 |
$string =~ s{<}{<}gso; |
| 45 |
$string =~ s{>}{>}gso; |
| 46 |
$string =~ s{"}{"}gso; |
| 47 |
return $string; |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
my $uri = URI::file->new( |
| 52 |
File::Spec->rel2abs( |
| 53 |
File::Spec->catfile( |
| 54 |
File::Spec->curdir(), "t", "data", "callbacks_returning_undef.xml" |
| 55 |
) |
| 56 |
) |
| 57 |
); |
| 58 |
|
| 59 |
my $esc_path = _escape_html("$uri"); |
| 60 |
|
| 61 |
my $string = <<"EOF"; |
| 62 |
<?xml version="1.0" encoding="us-ascii"?> |
| 63 |
<!DOCTYPE foo [ |
| 64 |
<!ENTITY foo SYSTEM "${esc_path}"> |
| 65 |
]> |
| 66 |
<methodCall> |
| 67 |
<methodName>metaWeblog.newPost</methodName> |
| 68 |
<params> |
| 69 |
<param> |
| 70 |
<value><string>Entity test: &foo;</string></value> |
| 71 |
</param> |
| 72 |
</params> |
| 73 |
</methodCall> |
| 74 |
EOF |
| 75 |
|
| 76 |
my $icb = XML::LibXML::InputCallback->new(); |
| 77 |
|
| 78 |
my $match_ret = 1; |
| 79 |
$icb->register_callbacks( [ |
| 80 |
sub { |
| 81 |
my $uri = shift; |
| 82 |
# skip for XML catalogs in /etc/xml/ |
| 83 |
return 0 if $uri =~ m{^file:///etc/xml/}; |
| 84 |
my $to_ret = $match_ret; $match_ret = 0; return $to_ret; |
| 85 |
}, |
| 86 |
sub { return undef; }, |
| 87 |
undef, |
| 88 |
undef |
| 89 |
] |
| 90 |
); |
| 91 |
|
| 92 |
my $parser = XML::LibXML->new(); |
| 93 |
$parser->input_callbacks($icb); |
| 94 |
my $num_warnings = 0; |
| 95 |
{ |
| 96 |
local $^W = 1; |
| 97 |
local $SIG{__WARN__} = sub { |
| 98 |
$num_warnings++; |
| 99 |
}; |
| 100 |
my $doc = $parser->parse_string($string); |
| 101 |
} |
| 102 |
# TEST |
| 103 |
is ($num_warnings, 0, "No warnings were recorded."); |