aizu-m opened a new pull request, #171:
URL: https://github.com/apache/poi-xmlbeans/pull/171

   `XmlObject.validate()` on a document with a `fixed` xsd:QName value throws 
instead of reporting the error through the listener:
   
       org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException: Invalid 
QName value: Can't resolve prefix 'p'
           at 
org.apache.xmlbeans.impl.values.JavaQNameHolder.parse(JavaQNameHolder.java:135)
           at 
org.apache.xmlbeans.impl.values.XmlObjectBase.setStringValue(XmlObjectBase.java:1773)
           at 
org.apache.xmlbeans.impl.schema.SchemaTypeImpl.newValue(SchemaTypeImpl.java:1873)
           at 
org.apache.xmlbeans.impl.validator.Validator.validateSimpleType(Validator.java:1058)
           ...
           at org.apache.xmlbeans.impl.store.Xobj.validate(Xobj.java:1787)
   
   Found while diffing `validate()` against the JDK Xerces validator over fixed 
and default value constraints.
   
   Observations:
   - The fixed-value branch of `validateSimpleType` builds 
`type.newValue(value)` and `type.newValue(fixedValue)` with no 
`NamespaceContext` pushed.
   - For an xsd:QName or xsd:NOTATION fixed value (also a list or union 
containing one) the prefix cannot be resolved, so `newValue` raises 
`XmlValueOutOfRangeException`, a `RuntimeException`, out of `validate()`. 
Reachable from any untrusted instance whose schema puts `fixed` on a QName 
typed element or attribute.
   - The enumeration comparisons a few lines down already push `new 
NamespaceContext(event)` and catch `XmlValueOutOfRangeException`. The 
fixed-value comparison was the one that did not.
   - The fixed value was resolved against the schema at compile time; 
`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-elt` or `cvc-au` fixed 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.
   
   `FixedQNameValidateTest` throws on trunk and passes with the change. 
`./gradlew test` is green (3333 tests).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to