Menu

#108 Pattern restriction does not work correctly with Unicode.

PyXB 1.1.4
closed
fixed
Binding model
major
PyXB 1.1.3
defect
2011-09-19
2011-09-19
Roger Dahl
No

PyXB raises BadTypeValueError on some Unicode strings that should be valid according to the regular expression.

To reproduce, create TestPatternRestriction.xsd schema:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
    <xs:simpleType name="TestPatternRestriction">
        <xs:restriction base="xs:string">
            <xs:pattern value=".*"/>
        </xs:restriction>
    </xs:simpleType>

    <xs:element name="test" type="TestPatternRestriction" />    
</xs:schema>

Create binding:

pyxbgen -u 'TestPatternRestriction.xsd' -m 'TestPatternRestriction'

Create script:

1
2
3
4
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import TestPatternRestriction as t
xml=u"
1 Attachments

Discussion

  • Roger Dahl

    Roger Dahl - 2011-09-19

    Trac truncated the submission at the location of the Unicode character in the example script. Here is the script again, this time with the unicode character represented as a \u escape sequence:

    1
    2
    3
    4
    5
    6
    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    import TestPatternRestriction as t
    xml=u"\U00010314";
    p = t.TestPatternRestriction(xml)
    print p.toxml()
    

    Error message (even though the ".*" regular expression in the restriction should match the Unicode character:

    BadTypeValueError(u'pattern violation for \U00010314 in TestPatternRestriction',)
    
     
  • Peter A. Bigot

    Peter A. Bigot - 2011-09-19

    Patch to correct wide unicode support detection

     
  • Peter A. Bigot

    Peter A. Bigot - 2011-09-19
    • status changed from new to closed
    • resolution set to fixed

    Fixed in following commit, available on branch "next".

    commit 652a2cf38ac5b8d66303a25520e6c0a33578ba27
    Author: Peter A. Bigot <pabigot@‌>
    Date: Mon Sep 19 18:27:43 2011 -0500

    trac/108: Pattern restriction does not work correctly with Unicode

    Fix error in syntax of test for wide unicode support.

     
MongoDB Logo MongoDB