Skip to content

Fix numeric input range matching with exponents - #317

Merged
facelessuser merged 1 commit into
facelessuser:mainfrom
repzakske:fix/numeric-exponent-ranges
Oct 17, 2026
Merged

facelessuser merged 1 commit into
facelessuser:mainfrom
repzakske:fix/numeric-exponent-ranges

Conversation

@repzakske

Copy link
Copy Markdown
Contributor

Scientific notation is part of HTML's valid floating-point syntax, but Inputs.parse_value() rejects it. As a result, a value such as 1e2 is treated as missing, and exponent-form min / max bounds are ignored.

For example:

from bs4 import BeautifulSoup

soup = BeautifulSoup(
    '<input type="number" min="0" max="10" value="1e2">',
    "html.parser",
)
soup.select(":out-of-range")  # currently []; should contain the input (100 > 10)

Accept an optional signed exponent after the significand. Reject non-finite conversion results so overflow such as 1e9999 remains invalid, in accordance with HTML's floating-point conversion rules.

Add regressions for both range pseudo-classes and both numeric input types, using all three HTML parsers in the existing test helper. They cover values and bounds, upper/lowercase exponents, positive/negative exponent signs, negative and fractional significands, malformed exponents, and overflow. Include an unreleased changelog entry.

Validation on Windows:

  • Both new regression tests fail against the original source.
  • Full suite on Python 3.11.16, 3.14.8, and 3.15.0: 413 passed, 1 skipped, with 100% source line coverage on each.
  • Ruff and strict mypy pass.
  • Wheel and source distribution builds pass; git diff --check passes.

Other operating systems and the remaining Python versions have not been tested locally.

@gir-bot gir-bot added S: needs-review Needs to be reviewed and/or approved. C: css-level-4 CSS level 4 selectors. C: css-matching Related to CSS matching. C: docs Related to documentation. C: source Related to source code. C: tests Related to testing. labels Oct 15, 2026
@facelessuser

Copy link
Copy Markdown
Owner

@gir-bot lgtm

@gir-bot gir-bot added S: approved The pull request is ready to be merged. and removed S: needs-review Needs to be reviewed and/or approved. labels Oct 17, 2026
@facelessuser
facelessuser merged commit b409c8f into facelessuser:main Oct 17, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C: css-level-4 CSS level 4 selectors. C: css-matching Related to CSS matching. C: docs Related to documentation. C: source Related to source code. C: tests Related to testing. S: approved The pull request is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants