I've been using PyXB to generate XML code from XSD templates for a while,
and  it works most of the time.

But today I've found a pretty serious bug in Pattern validation.

<xs:simpleType name="tpEmail">
    <xs:annotation>
      <xs:documentation>Tipo E-mail.</xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:string">
      <xs:minLength value="0" />
      <xs:maxLength value="75" />
      <xs:whiteSpace value="collapse" />
      <xs:pattern
value="([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})"
/>
    </xs:restriction>
  </xs:simpleType>

The pattern above failed to validate the email r_go...@hotmail.com, because
of the underscore. The problema is: the pattern allows an underscore, and
I've tested it directly on a python shell:

>>> m =
re.match("([0-9a-zA-Z]([-.\\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\\w]*[0-9a-zA-Z]\\.)+[a-zA-Z]{2,9})",
"r_co...@hotmail.com")
>>> m.group()
'r_co...@hotmail.com'
Digging the code, it seems that the problem is the XMLToPython, that is
supposed to translate an XML pattern to a Python Pattern.
The _PatternElement class uses it to build the python regexp object
(facets.py, line 388). When I removed this conversion, everything worked.

Can someone help to understand if this is really a bug?

Tks

Miguel Galves - Engenheiro de Computação

"Não sabendo que era impossível, ele foi lá e fez..."
"Stay hungry, stay foolish"
------------------------------------------------------------------------------
_______________________________________________
pyxb-users mailing list
pyxb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyxb-users

Reply via email to