shlomif / perl-XML-LibXML

The XML-LibXML CPAN Distribution for Processing XML using the libxml2 library
https://metacpan.org/release/XML-LibXML
Other
17 stars 35 forks source link

$document->URI is sometimes percent encoded, but not always #44

Open choroba opened 4 years ago

choroba commented 4 years ago
#!/usr/bin/perl
use warnings;
use strict;
use feature qw{ say };

use XML::LibXML;

for my $file (qw( 1%3Ab.xml 1:b.xml )) {
    open my $out, '>', $file or die "$file: $!";
    print {$out} "<r>$file</r>";
    close $out;

    my $dom = 'XML::LibXML'->load_xml(location => $file);
    say $dom->URI;
    unlink $file;
}

This returns:

1%3Ab.xml
1%3Ab.xml

The problem lies in the underlying libxml2 library, see Filenames starting with a digit are stored percent encoded in xmlDoc.URL.

The upstream isn't going to fix the bug, but maybe we can workaround it in XML::LibXML? I haven't investigated whether it's possible, yet.