perl-XML-LibXML / t / 49callbacks_returning_undef.t

# This is a bug fix for:
# When the match callback returns 1 and the open callback returns undef, then the
# read callback (inside the XS code) warnings about:
# "Use of uninitialized value in subroutine entry at".
# This is due to the value returned being undef and processed by SvPV.

use strict;
use warnings;

use lib './t/lib';

use Test::More;
use File::Spec;

use XML::LibXML;

if (! eval { require URI::file; } )
    plan skip_all => "URI::file is not available.";
    plan tests => 1;

sub _escape_html
    my $string = shift;
    $string =~ s{&}{&}gso;
    $string =~ s{<}{&lt;}gso;
    $string =~ s{>}{&gt;}gso;
    $string =~ s{"}{&quot;}gso;
    return $string;

my $uri = URI::file->new(
            File::Spec->curdir(), "t", "data", "callbacks_returning_undef.xml"

my $esc_path = _escape_html("$uri");

my $string = <<"EOF";
<?xml version="1.0" encoding="us-ascii"?>
<!DOCTYPE foo [
    <!ENTITY foo SYSTEM "${esc_path}">
      <value><string>Entity test: &foo;</string></value>

my $icb    = XML::LibXML::InputCallback->new();

my $match_ret = 1;
$icb->register_callbacks( [ 
        sub { my $to_ret = $match_ret; $match_ret = 0; return $to_ret; }, 
        sub { return undef; },

my $parser = XML::LibXML->new();
my $num_warnings = 0;
    local $^W = 1;
    local $SIG{__WARN__} = sub {
    my $doc = $parser->parse_string($string);
is ($num_warnings, 0, "No warnings were recorded.");
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.