Repository navigation
🐛 fix(xsd): reject NaN under bounded float facets - #1968
Conversation
The four range checks in facet_check() tested for the violation, such as number < minInclusive. An ordered comparison with NaN is false, so NaN passed every bound and XMLSchema reported a NaN value of a bounded xs:double or xs:float as valid. XML Schema Part 2 excludes NaN from such a type, and the RELAX NG validator already rejects it. The checks now negate what each facet requires, so an unordered NaN fails every bound. Finite values and infinities get the same verdicts as before, and an unbounded NaN stays valid.
Merging this PR will improve performance by 7.1%2 warnings
Performance Changes
Tip Curious why performance improved? Comment Comparing Footnotes
|
XML Schema makes NaN equal to itself and unordered with every other float or double. An inclusive NaN bound therefore admits only NaN, and an exclusive NaN bound admits no value. Both validators rejected every value instead, NaN included. Decimal and integer bounds were compared as doubles, which rounds long literals: a negative value too small for a double read as zero and passed minInclusive 0, and integers past 2^53 compared equal to their neighbors. Range facets on decimal and integer types now compare the digits as written. List items and RELAX NG datatypes follow the same rules. Refs tox-dev#1736, follows tox-dev#1968.
XMLSchemaaccepted a NaN element or attribute value of a boundedxs:doubleorxs:floatas valid. The range checks rejected a value only when a comparison was true, and every comparison with NaN is false, so NaN passed every bound. ⚡ Once this merges, NaN fails the bounds and is reported with the existing below or above message, as RELAX NG validation already does. Fixes #1736XML Schema excludes NaN from a bounded float or double (XML Schema Part 2). 🧭 Each range check now rejects a value that does not meet its facet, instead of one that breaks it. For two ordered numbers the two forms agree, so finite values and infinities keep their verdicts.
xs:doubleorxs:floatis now invalid.