willemdj / erlsom

XML parser for Erlang
GNU Lesser General Public License v3.0
266 stars 103 forks source link

regression bug on "any" elements #48

Closed zuckschwerdt closed 8 years ago

zuckschwerdt commented 8 years ago

As far as I can tell ab14ec6 introduced a bug when handling "any" elements. Using a ab14ec6_bug.xsd schema of (simplified from some SOAP and WSDL):

<?xml version="1.0" encoding="UTF-8"?>
<schema targetNamespace="urn:example:tns"
    xmlns="http://www.w3.org/2001/XMLSchema"
    xmlns:tns="urn:example:tns"
    elementFormDefault="qualified" attributeFormDefault="unqualified">

  <element name="Body" type="tns:Body" />
  <complexType name="Body" >
    <sequence>
      <any namespace="##any" processContents="lax" minOccurs="0" maxOccurs="unbounded" />
    </sequence>
    <anyAttribute namespace="##other" processContents="lax" />
  </complexType>

  <complexType name="RequestBaseType" />

  <element name="SignRequest" type="tns:RequestBaseType"></element>

  <element name="ArchiveSubmissionRequest">
    <complexType>
      <complexContent>
        <extension base="tns:RequestBaseType" />
      </complexContent>
    </complexType>
  </element>

</schema>

I noticed:

% erl -pa ebin

{ok, Model} = erlsom:compile_xsd_file("ab14ec6_bug.xsd").
Request = {'ArchiveSubmissionRequest', undefined}.
Body = {'Body', undefined, [Request]}.
erlsom:write(Body, Model).

% expected: (works up to e2ab569)
% {ok,"<Body xmlns=\"urn:example:tns\"><ArchiveSubmissionRequest/></Body>"}

% actual: (broken since ab14ec6)
% {ok,"<Body xmlns=\"urn:example:tns\"><SignRequest xsi:type=\"ArchiveSubmissionRequest\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/></Body>"}

I'll try to debug this further.

For quick reference, the model here is:

{model,[{type,'_document',sequence,
                  [{el,[{alt,'Body','Body',[],1,1,true,undefined},
                        {alt,'SignRequest','RequestBaseType',[],1,1,true,undefined},
                        {alt,'ArchiveSubmissionRequest','ArchiveSubmissionRequest',
                             [],1,1,true,undefined}],
                       1,1,undefined,3}],
                  [],undefined,undefined,1,1,1,false,undefined},
            {type,'ArchiveSubmissionRequest',sequence,[],[],undefined,
                  undefined,1,1,1,undefined,'ArchiveSubmissionRequest'},
            {type,'RequestBaseType',sequence,[],[],undefined,undefined,
                  1,1,1,undefined,undefined},
            {type,'Body',sequence,
                  [{el,[{alt,'#any',any,[],1,1,true,
                             {anyInfo,"lax","##any","urn:example:tns"}}],
                       0,unbound,undefined,3}],
                  [],
                  {anyAttr,"lax","##other","urn:example:tns"},
                  undefined,2,1,1,undefined,undefined}],
           [{ns,"http://www.w3.org/2001/XMLSchema","xsd"},
            {ns,"urn:example:tns",undefined}],
           "urn:example:tns",
           [{'ArchiveSubmissionRequest','RequestBaseType'}],
           true,skip}

Earlier it used to be:

{model,[{type,'_document',sequence,
                  [{el,[{alt,'Body','Body',[],1,1,true,undefined},
                        {alt,'SignRequest','RequestBaseType',[],1,1,true,undefined},
                        {alt,'ArchiveSubmissionRequest','ArchiveSubmissionRequest',
                             [],1,1,true,undefined}],
                       1,1,undefined,3}],
                  [],undefined,undefined,1,1,1,false,undefined},
            {type,'ArchiveSubmissionRequest',sequence,[],[],undefined,
                  undefined,1,1,1,undefined,'ArchiveSubmissionRequest'},
            {type,'RequestBaseType',sequence,[],[],undefined,undefined,
                  1,1,1,undefined,undefined},
            {type,'Body',sequence,
                  [{el,[{alt,'#any',any,[],1,1,true,
                             {anyInfo,"lax","##any","urn:example:tns"}},
                        {alt,'ArchiveSubmissionRequest','ArchiveSubmissionRequest',
                             [],1,1,true,undefined},
                        {alt,'SignRequest','RequestBaseType',[],1,1,true,undefined},
                        {alt,'Body','Body',[],1,1,true,undefined}],
                       0,unbound,undefined,3}],
                  [],
                  {anyAttr,"lax","##other","urn:example:tns"},
                  undefined,2,1,1,undefined,undefined}],
           [{ns,"http://www.w3.org/2001/XMLSchema","xsd"},
            {ns,"urn:example:tns",undefined}],
           "urn:example:tns",
           [{'ArchiveSubmissionRequest','RequestBaseType'}],
           true,skip}
willemdj commented 8 years ago

Sorry about that. Thanks for the detailed report. I'll look into it, and add it as a case to my regeression test set.

regards, Willem

willemdj commented 8 years ago

Solved the issue.