Skip to content

reject non-finite values in parse_decimal#1277

Open
digi-scrypt wants to merge 1 commit into
python-babel:masterfrom
digi-scrypt:parse-decimal-reject-nonfinite
Open

reject non-finite values in parse_decimal#1277
digi-scrypt wants to merge 1 commit into
python-babel:masterfrom
digi-scrypt:parse-decimal-reject-nonfinite

Conversation

@digi-scrypt

Copy link
Copy Markdown
  1. parse_decimal builds the result straight from decimal.Decimal(...), which happily accepts nan, inf, Infinity and sNaN, so those parse instead of being rejected.
  2. a NaN result then slips past range checks (every comparison against NaN is False), and a signaling NaN throws InvalidOperation the first time anything does arithmetic with it.

Added an is_finite() check so non-finite input raises NumberFormatError like any other non-decimal string. What happens today if someone feeds "inf" from a form field straight into a > limit guard? It passes. Kept it in the parser since that's the layer that already promises to reject things that aren't localized decimals.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant