Closed vient closed 6 years ago
The fix is available with release 0.9.29 (also for base64binary types).
Those types now use other validation functions (look at hex_length_validator()
, hex_min_length_validator()
and hex_max_length_validator()
methods in facets.py).
Thanks
I don't think you can use same validator for hex
and base64
. If I understand documentation right, length restrictions are given for decoded data, in case of hex
it is indeed 2 * encoded_length
but for base64
it is encoded_length * 4 / 3
(maybe it's possible to miss some =
placeholders in the end so final formula will be a little more complicated).
Also, from base64Binary
you got XSD_BASE46_BINARY
(46 instead of 64).
Yes, you are right. I made confusion between padded and unpadded data. So the base64 length validator maybe written as:
def base64_length_validator(self, x):
x = x.replace(' ', '')
if (len(x) // 4 * 3 - (x[-1] == '=') - (x[-2] == '=')) != self.value:
yield XMLSchemaValidationError(self, x)
The same formula can be used for a min and max length validators.
Should be fixed with release 0.9.30.
Consider checking this example:
using
wml.xsd
scheme provided in ECMA-376 2nd edition Part 4. You will get following error:After deleting 2 out of 4 octets document passes checking. In docs it is said that length of
hexBinary
element is counted in octets, not characters: https://www.w3.org/TR/xmlschema-2/#rf-length, so the xmlschema is wrong here.