After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 457889 - elementFormDefault and key selector doesn't work with empty namespace prefix
elementFormDefault and key selector doesn't work with empty namespace prefix
Status: RESOLVED OBSOLETE
Product: libxml2
Classification: Platform
Component: xmlschema
2.6.26
Other All
: Normal normal
: ---
Assigned To: Daniel Veillard
libxml QA maintainers
Depends on:
Blocks:
 
 
Reported: 2007-07-18 09:21 UTC by Axel Jurke
Modified: 2021-07-05 13:26 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Axel Jurke 2007-07-18 09:21:54 UTC
Please describe the problem:
If a schema uses elementFormDefault and the namespace prefix of the target namespace is empty, the uniqueness of the key constraints is not testet anymore.

Steps to reproduce:
Run xmllint with the following schema:
<xsd:schema targetNamespace="http://www.example.com/a"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns="http://www.example.com/a"
        elementFormDefault="qualified">
  <xsd:element name="a">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="b" type="bType"/>
      </xsd:sequence>
    </xsd:complexType>
    <xsd:key name="bKey">
      <xsd:selector xpath="b/c"/>
      <xsd:field xpath="@n"/>
    </xsd:key>
  </xsd:element>
  <xsd:complexType name="bType">
    <xsd:sequence>
      <xsd:element name="c" maxOccurs="unbounded">
        <xsd:complexType>
          <xsd:simpleContent>
            <xsd:extension base="xsd:string">
              <xsd:attribute name="n" type="xsd:positiveInteger"/>
            </xsd:extension>
          </xsd:simpleContent>
        </xsd:complexType>
      </xsd:element>
    </xsd:sequence>
  </xsd:complexType>
</xsd:schema>

and the XML file:
<a xmlns="http://www.example.com/a">
    <b>
        <c n="1"/>
        <c n="1"/>
        <c n="2"/>
        <c n="3"/>
    </b>
</a>

Actual results:
xmllint validates the file although the key values are not unique.

Expected results:
I expected xmllint to report the following error:
x.xml:4: element c: Schemas validity error : Element '{http://www.example.com/a}c': Duplicate key-sequence ['1'] in key identity-constraint '{http://www.example.com/a}bKey'.

Does this happen every time?


Other information:
The problem seems to be that the function xmlCompileStepPattern() doesn't handle empty namespace prefixes. If I add the code below (in version 2.6.27) the nonunique key is detected, but I guess this code has side effects, which causes even more problems.
diff -r libxml2-2.6.27/pattern.c libxml2-2.6.27.mod/pattern.c
1204c1204,1216
<       PUSH(XML_OP_ELEM, name, NULL);
---
>       /* if( elementFormDefault="qualified" ) */
>       if( 1 ) {
>           int i;
>           for (i = 0;i < ctxt->nb_namespaces;i++) {
>               if( ctxt->namespaces[2 * i + 1] == NULL
>                 || xmlStrEqual(ctxt->namespaces[2 * i + 1], "")
>               ) {
>                   XML_PAT_COPY_NSNAME(ctxt, URL, ctxt->namespaces[2 * i])
>                   break;
>               }
>           }
>       }
>       PUSH(XML_OP_ELEM, name, URL);
Comment 1 GNOME Infrastructure Team 2021-07-05 13:26:02 UTC
GNOME is going to shut down bugzilla.gnome.org in favor of gitlab.gnome.org.
As part of that, we are mass-closing older open tickets in bugzilla.gnome.org
which have not seen updates for a longer time (resources are unfortunately
quite limited so not every ticket can get handled).

If you can still reproduce the situation described in this ticket in a recent
and supported software version, then please follow
  https://wiki.gnome.org/GettingInTouch/BugReportingGuidelines
and create a new ticket at
  https://gitlab.gnome.org/GNOME/libxml2/-/issues/

Thank you for your understanding and your help.