Skip to content

🐛 fix(xsd): check NaN and decimal range bounds - #2242

Merged
gaborbernat merged 1 commit into
tox-dev:mainfrom
gaborbernat:fix/xsd-nan-facets-1736
Nov 16, 2026
Merged

gaborbernat merged 1 commit into
tox-dev:mainfrom
gaborbernat:fix/xsd-nan-facets-1736

Conversation

@gaborbernat

Copy link
Copy Markdown
Member

XML Schema validation mis-judged some range facets. An inclusive NaN bound on xs:float or xs:double rejected every value, NaN included, although XML Schema Part 2 makes NaN equal to itself, so the only value such a bound admits is NaN. #1968 fixed NaN values under bounded facets and left this case open. Decimal and integer bounds were also compared as doubles, so values that differ only beyond double precision were ranked the same way against a bound, and a long negative value too small for a double passed minInclusive 0. Once this merges, NaN bounds, list items and long decimal and integer values get the verdict the specification gives. This fixes #1736 and covers the decimal bounds that #2164 left open, tracked in #2232. 🔢

The float path keeps IEEE doubles and applies one bound rule that treats NaN the way XML Schema does, in both the XSD and the RELAX NG datatype check. Decimal and integer facets use the order path that dates already use: each bound is compared with its value as written, digit by digit, with no conversion to a double. The shared order function decides both validators, so they agree on every bound.

Behavior changes

  • An inclusive NaN bound on a float or double admits only NaN. An exclusive NaN bound admits no value, as before.
  • A decimal or integer bound is compared exactly. Values that differ only beyond double precision are now ranked by their digits.
  • A bound on a decimal or integer facet that is not a decimal literal, such as abc, rejects every value. It used to compare as zero.
  • The length facets and the digit facets (totalDigits, fractionDigits) still read their limits as doubles. They are tracked in #2232.

@gaborbernat gaborbernat added bug Something isn't working and removed bug Something isn't working labels Nov 16, 2026
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.
@gaborbernat
gaborbernat force-pushed the fix/xsd-nan-facets-1736 branch from 1ebf58c to d617fa3 Compare November 16, 2026 19:45
@codspeed

codspeed Bot commented Nov 16, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 19.21%

1 warning, 1 note

⚠️ 1 benchmark with a significant change ran in a different software environment

Its base and head results were measured with a different OS or toolchain, such as compiler, runtime or library versions, so the change might come from this difference rather than from the code. Open the benchmark to see what changed.

See affected benchmarks

ℹ️ This run is excluded from the branch history

This commit was force-pushed, so this run no longer appears in the branch's performance history.

⚡ 1 improved benchmark
✅ 581 untouched benchmarks
⏩ 89 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ test_feature[validate-numeric-facets-bounded] 368 µs 308.7 µs +19.21%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing gaborbernat:fix/xsd-nan-facets-1736 (1ebf58c) with main (7e6d0f9)

Open in CodSpeed

Footnotes

  1. 89 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@gaborbernat
gaborbernat merged commit 20fffbe into tox-dev:main Nov 16, 2026
3 of 45 checks passed
@gaborbernat gaborbernat added the bug Something isn't working label Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

XMLSchema accepts NaN for bounded xs:double and xs:float

1 participant