Skip Menu |

This queue is for tickets about the XML-Compile CPAN distribution.

Report information
The Basics
Id: 41725
Status: resolved
Priority: 0/
Queue: XML-Compile

People
Owner: Nobody in particular
Requestors: osfameron [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: 0.97
Fixed in:
  • 0.64
  • 0.67



Hi Markov :-) We upgraded to 0.97 today and immediately had a problem with our schema failing to compile messages that had a minOccurs="0": we've worked around in the one failing case... but it could manifest itself in other cases too... Gareth and I investigated, and have found that the problem seems to be while processing the containing <xs:sequence> BLOCK. The latest version of XC defaults to min=1, even though the contained block is intended to be optional. The attached test case with an extract from our schema should make this clear - but please let me know if there are additional tests or information that I can provide to help debug! Thanks for providing X::C and for any time that you have to help resolve! Hakim
Subject: xml-compile.t
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use XML::Compile::Schema; use XML::Compile::Translate::Writer; use XML::LibXML; =head1 NAME Bug report minOccurs for L<XML::Compile> =head2 Worked in 0.64-0.69 =head2 Broken in 0.97 =head2 Reported by hakim@thermeon.com, 2008-12-15 =cut use Test::More tests=>2; use Test::Exception; my $schema = do { local $/=undef; <DATA> }; my $doc = XML::LibXML::Document->new('1.0', 'UTF-8'); my %hash = ( 'ResRates' => { 'Count' => 4, 'Messages' => { 'Message' => [ { number => 12, type => 'Error', Text => 'Example' } ] } } ); test_xml( "Sanity check", $schema, $doc, \%hash ); $hash{ResRates}{Messages}{Message} = []; # this should be fine too (as Message is numOccurs="0") test_xml( "With zero messages", $schema, $doc, \%hash ); sub test_xml { my ($desc, $schema_data, $doc, $hash) = @_; my $schema = XML::Compile::Schema->new( $schema_data ); my $write = $schema->compile( WRITER => '{http://www.thermeon.com/webXG/xml/webxml/}Response', use_default_prefix => 1, ); lives_ok { my $xml = $write->($doc, $hash); # diag $xml->toString; } $desc; } __DATA__ <?xml version="1.0" encoding="UTF-8"?> <!-- $Revision: 1060 $ --> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.thermeon.com/webXG/xml/webxml/" xmlns="http://www.thermeon.com/webXG/xml/webxml/" elementFormDefault="qualified"> <xs:element name="Response"> <xs:complexType> <xs:choice> <xs:element name="ResRates"> <xs:complexType> <xs:sequence> <xs:element name="Count" type="xs:int" /> <xs:element name="Messages" minOccurs="0"> <xs:complexType> <xs:sequence> <xs:element name="Message" type="MessageType" minOccurs="0" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:choice> </xs:complexType> </xs:element> <xs:complexType name="MessageType"> <xs:sequence> <xs:element name="Text" type="xs:string"/> </xs:sequence> <xs:attribute name="number" type="xs:string" use="optional"/> <xs:attribute name="type"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="Question" /> <xs:enumeration value="Info" /> <xs:enumeration value="Warning" /> <xs:enumeration value="Error" /> <xs:enumeration value="Critical" /> </xs:restriction> </xs:simpleType> </xs:attribute> </xs:complexType> <xs:complexType name="MessagesType"> <xs:sequence> <xs:element name="Message" type="MessageType" minOccurs="0" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> </xs:schema>
Subject: Re: [rt.cpan.org #41725]
Date: Mon, 15 Dec 2008 21:18:26 +0100
To: osfameron via RT <bug-XML-Compile [...] rt.cpan.org>
From: Mark Overmeer <mark [...] overmeer.net>
* osfameron via RT (bug-XML-Compile@rt.cpan.org) [081215 17:08]: Show quoted text
> Mon Dec 15 12:08:09 2008: Request 41725 was acted upon. > Transaction: Ticket created by OSFAMERON > Queue: XML-Compile > Subject: (No subject given) > Broken in: 0.97 > > We upgraded to 0.97 today and immediately had a problem with our schema > failing to compile messages that had a minOccurs="0": we've worked > around in the one failing case... but it could manifest itself in other > cases too...
Nasty things, two-level optionals... Change in the writer: sub makeElementHandler { my ($self, $path, $label, $min, $max, $required, $optional) = @_; $max eq "0" and return sub {}; if($min==0 && $max eq 'unbounded') { return sub { my ($doc, $values) = @_; + my @values = ref $values eq 'ARRAY' ? @$values + : defined $values ? $values : (); + @values ? map {$optional->($doc,$_)} @$values : (undef); }; } I am glad you complained, and did not go for the work-around delete $hash{ResRates}{Messages}{Message}; There will be a new release tomorrow. -- Regards, MarkOv ------------------------------------------------------------------------ Mark Overmeer MSc MARKOV Solutions Mark@Overmeer.net solutions@overmeer.net http://Mark.Overmeer.net http://solutions.overmeer.net
On Mon Dec 15 15:18:41 2008, Mark@Overmeer.net wrote: Show quoted text
> * osfameron via RT (bug-XML-Compile@rt.cpan.org) [081215 17:08]: > Nasty things, two-level optionals... Change in the writer:
<snip> Show quoted text
> I am glad you complained, and did not go for the work-around > delete $hash{ResRates}{Messages}{Message};
Glad it was useful :-) Actually, we did prevent that hash from getting created as a workaround in the first instance too... (but we did worry there might be other occurrences of the problem elsewhere) Show quoted text
> There will be a new release tomorrow.
Yay! I saw your announcement for 0.98, I'll download today and test, thanks for the quick release! H
Subject: Re: [rt.cpan.org #41725]
Date: Tue, 16 Dec 2008 10:16:42 +0100
To: osfameron via RT <bug-XML-Compile [...] rt.cpan.org>
From: Mark Overmeer <mark [...] overmeer.net>
* osfameron via RT (bug-XML-Compile@rt.cpan.org) [081216 08:01]: Show quoted text
> Queue: XML-Compile > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=41725 > > > On Mon Dec 15 15:18:41 2008, Mark@Overmeer.net wrote:
> > * osfameron via RT (bug-XML-Compile@rt.cpan.org) [081215 17:08]: > > Nasty things, two-level optionals... Change in the writer:
> <snip>
> > I am glad you complained, and did not go for the work-around > > delete $hash{ResRates}{Messages}{Message};
> > Glad it was useful :-) Actually, we did prevent that hash from getting > created as a workaround in the first instance too... > (but we did worry there might be other occurrences of the problem elsewhere)
If everyone creates their own work-arounds, then the situation never gets improved... So, I am always happy with reports, and try to fix them within a day. -- MarkOv ------------------------------------------------------------------------ Mark Overmeer MSc MARKOV Solutions
got fixed in 0.98 (just released 1.00)