Subject: | XML::Compile::Schema::_parseFile sometimes caches two different schema as one |
Date: | Mon, 13 Jan 2014 12:23:12 +0800 |
To: | bug-XML-Compile [...] rt.cpan.org |
From: | Brendan Knox <mrevil [...] gmail.com> |
Hi,
I've encountered a small bug in the _parseFile() method when loading two
schema with the same file size, mtime and basename. Caching will hit on
two different files.
Schema file list:
#-rw-r--r-- 1 bknox bknox 455 2014-01-13 03:24 ../xmlschema/1.0/Shared.xsd
#-rw-r--r-- 1 bknox bknox 455 2014-01-13 03:24 ../xmlschema/2.0/Shared.xsd
Script:
use XML::Compile::Schema;
my $xsd1 = '../xmlschema/1.0/Shared.xsd';
my $xsd2 = '../xmlschema/2.0/Shared.xsd';
my $xcs = XML::Compile::Schema->new();
say "Importing $xsd1";
$xcs->importDefinitions( $xsd1 );
say "Loaded so far: $_" for ($xcs->namespaces->list);
say "Importing $xsd2";
$xcs->importDefinitions( $xsd2 );
say "Loaded so far: $_" for ($xcs->namespaces->list);
Output:
Importing ../xmlschema/1.0/Shared.xsd
Loaded so far: http://www.snoutlabs.net/xmlschema/1.0/Shared.xsd
Importing ../xmlschema/2.0/Shared.xsd
Loaded so far: http://www.snoutlabs.net/xmlschema/1.0/Shared.xsd
Potential patch:
--- Schema.pm 2014-01-13 04:20:29.000000000 +0000
+++ Schema.pm.fix 2014-01-13 04:20:11.000000000 +0000
@@ -16,8 +16,8 @@
use List::Util qw/first/;
use XML::LibXML ();
use File::Spec ();
-use File::Basename qw/basename/;
use Digest::MD5 qw/md5_hex/;
+use Cwd ();
use XML::Compile::Schema::Specs;
use XML::Compile::Schema::Instance;
@@ -468,7 +468,7 @@
my $self = $thing;
my ($mtime, $size) = (stat $fn)[9,7];
- my $filestamp = basename($fn) . '-'. $mtime . '-' . $size;
+ my $filestamp = Cwd::abs_path($fn) . '-'. $mtime . '-' . $size;
if($self->{_cache_file}{$filestamp})
{ trace "reusing schemas from file $filestamp";
Output after patch:
Importing ../xmlschema/1.0/Shared.xsd
Loaded so far: http://www.snoutlabs.net/xmlschema/1.0/Shared.xsd
Importing ../xmlschema/2.0/Shared.xsd
Loaded so far: http://www.snoutlabs.net/xmlschema/1.0/Shared.xsd
Loaded so far: http://www.snoutlabs.net/xmlschema/2.0/Shared.xsd
Cheers,
Brendan