kripken / xml.js

Port of libxml to JavaScript using Emscripten
Other
174 stars 67 forks source link

Seems to incorrectly validate unions of patterns. #13

Closed jacobmischka closed 7 years ago

jacobmischka commented 8 years ago

I'm creating an XML document adhering to this schema: https://www.aqihq.org/AQIXMLResources/AQISchema.xsd

The element name in question is ICDValueType, which is a union of 4 different patterns, one of those patterns containing multiple patterns between |s:

  <xs:simpleType name="ICDValueType">
    <xs:union memberTypes="ICDValueType9CM ICDValueType10CM ICDValueType9SG ICDValueType10SG" />
  </xs:simpleType>

  <xs:simpleType name="ICDValueType9CM">
    <xs:restriction base="xs:string">
      <xs:minLength value="3" />
      <xs:maxLength value="6" />
      <xs:pattern value="^(V\d{2}(\.\d{1,2})?|\d{3}(\.\d{1,2})?|E\d{3}(\.\d)?)$" />
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ICDValueType10CM">
    <xs:restriction base="xs:string">
      <xs:minLength value="3" />
      <xs:maxLength value="8" />
      <xs:pattern value="^[A-TV-Z][0-9][A-Z0-9](\.[A-Z0-9]{1,4})?$" />
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ICDValueType9SG">
    <xs:restriction base="xs:string">
      <xs:minLength value="3" />
      <xs:maxLength value="4" />
      <xs:pattern value="^\d{3,4}$" />
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ICDValueType10SG">
    <xs:restriction base="xs:string">
      <xs:minLength value="3" />
      <xs:maxLength value="5" />
      <xs:pattern value="^[a-zA-Z0-9]{7}$" />
    </xs:restriction>
  </xs:simpleType>

This library is incorrectly throwing errors for the center pattern in the ICDValueType9CM type:

...
file_0.xml:149: element ICDValue: Schemas validity error : Element '{https://www.aqihq.org/AQIXMLResources/AQISchema.xsd}ICDValue': '523.4' is not a valid value of the union type '{https://www.aqihq.org/AQIXMLResources/AQISchema.xsd}ICDValueType'.
file_0.xml:154: element ICDValue: Schemas validity error : Element '{https://www.aqihq.org/AQIXMLResources/AQISchema.xsd}ICDValue': '525.3' is not a valid value of the union type '{https://www.aqihq.org/AQIXMLResources/AQISchema.xsd}ICDValueType'.
file_0.xml:348: element ICDValue: Schemas validity error : Element '{https://www.aqihq.org/AQIXMLResources/AQISchema.xsd}ICDValue': '812.2' is not a valid value of the union type '{https://www.aqihq.org/AQIXMLResources/AQISchema.xsd}ICDValueType'.
file_0.xml:353: element ICDValue: Schemas validity error : Element '{https://www.aqihq.org/AQIXMLResources/AQISchema.xsd}ICDValue': '726.2' is not a valid value of the union type '{https://www.aqihq.org/AQIXMLResources/AQISchema.xsd}ICDValueType'.
file_0.xml:358: element ICDValue: Schemas validity error : Element '{https://www.aqihq.org/AQIXMLResources/AQISchema.xsd}ICDValue': '728.3' is not a valid value of the union type '{https://www.aqihq.org/AQIXMLResources/AQISchema.xsd}ICDValueType'.
file_0.xml:363: element ICDValue: Schemas validity error : Element '{https://www.aqihq.org/AQIXMLResources/AQISchema.xsd}ICDValue': '709.8' is not a valid value of the union type '{https://www.aqihq.org/AQIXMLResources/AQISchema.xsd}ICDValueType'.
...

I'm not particularly good at regex, so if I'm misunderstanding something please let me know, but as far as I can tell these values are valid examples of /\d{3}(\.\d{1,2})?/. Thank you.

jacobmischka commented 7 years ago

Regular xmllint throws the same errors I've come to realize, so it's not this package's fault.