File: 49global_extent.t

package info (click to toggle)
libxml-libxml-perl 2.0207%2Bdfsg%2Breally%2B2.0134-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,572 kB
  • sloc: perl: 6,310; ansic: 3,851; xml: 182; sh: 21; makefile: 16
file content (44 lines) | stat: -rw-r--r-- 772 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use strict;
use warnings;

use Test::More;
use XML::LibXML;

if (XML::LibXML::LIBXML_VERSION() < 20627) {
    plan skip_all => "skipping for libxml2 < 2.6.27";
}
else
{
    plan tests => 1;
}

sub handler {
  return "ENTITY:" . join(",",@_);
}

# global entity loader
XML::LibXML::externalEntityLoader(\&handler);

my $parser = XML::LibXML->new({
  expand_entities => 1,
});

my $xml = <<'EOF';
<?xml version="1.0"?>
<!DOCTYPE foo [
<!ENTITY a PUBLIC "//foo/bar/b" "file:/dev/null">
<!ENTITY b SYSTEM "file:///dev/null">
]>
<root>
  <a>&a;</a>
  <b>&b;</b>
</root>
EOF
my $xml_out = $xml;
$xml_out =~ s{&a;}{ENTITY:file:/dev/null,//foo/bar/b};
$xml_out =~ s{&b;}{ENTITY:file:///dev/null,};

my $doc = $parser->parse_string($xml);

# TEST
is( $doc->toString(), $xml_out );