Repository navigation
Conversation
pjfanning
left a comment
There was a problem hiding this comment.
Thanks, comparing against the compiled fixed value is the right approach. Two points:
1. The fixed value's prefix is still resolved against the instance before the comparison
Just above the changed block, Validator.java:1054 still runs
if (!validateSimpleType(type, fixedValue, event)) {
return null;
}That checks the lexical fixed value, with the schema's prefix in it, against the instance's namespace declarations. So an instance that reaches the fixed namespace through its own prefix, and never declares p, is still rejected with a "can't resolve prefix 'p'" error:
<!-- schema: xmlns:p='urn:p', fixed='p:foo' -->
<t:qn xmlns:t='urn:t' xmlns:z='urn:p'>z:foo</t:qn>fixedQNameComparedByValueNotPrefix passes only because it also declares xmlns:p='urn:p' on the instance, which hides this.
Suggestion: when field.getDefaultValue() is non-null, skip the lexical check of fixedValue, since it was already validated at compile time. Keep the check only for the fallback that reparses fixedValue. Please also add the case above, with p undeclared, to the test.
2. Minor: the two sides of the comparison may now have different types
The compiled value has the field's declared type, while val is built from type, which can be a different type set via xsi:type. Before, both sides came from type.newValue(...). This is probably fine, since valueEquals compares by primitive type, but a test with xsi:type on a fixed element would confirm it.
The lexical check resolved the schema's prefix against the instance, so an instance that reached the fixed namespace through its own prefix was still rejected. It is only needed for the fallback that reparses the lexical form. Covers the undeclared schema prefix and an xsi:type narrowed instance type.
|
Both done. 1. Confirmed. With the comparison fixed but the lexical check left in, if (def == null && !validateSimpleType(type, fixedValue, event)) {
return null;
}
2. Added Both new cases fail on the previous commit. |
XmlObject.validate()on a document with afixedxsd:QName value throws instead of reporting the error through the listener:Found while diffing
validate()against the JDK Xerces validator over fixed and default value constraints.Observations:
validateSimpleTypebuildstype.newValue(value)andtype.newValue(fixedValue)with noNamespaceContextpushed.newValueraisesXmlValueOutOfRangeException, aRuntimeException, out ofvalidate(). Reachable from any untrusted instance whose schema putsfixedon a QName typed element or attribute.new NamespaceContext(event)and catchXmlValueOutOfRangeException. The fixed-value comparison was the one that did not.field.getDefaultValue()already holds the cooked QName. Reparsing its lexical form in the instance context is wrong anyway, as it resolves the schema prefix against the instance.Conclusion: push the namespace context for the instance value and compare against the compiled fixed value. A wrong value is now reported as the usual
cvc-eltorcvc-aufixed error rather than thrown, a value that reaches the fixed namespace through a different instance prefix still matches, and a prefix rebound to another namespace does not. Non-QName fixed values behave as before.FixedQNameValidateTestthrows on trunk and passes with the change../gradlew testis green (3333 tests).