From e8b7a73d1f9b1887174c31e00df302d6c97370be Mon Sep 17 00:00:00 2001 From: ctan Date: Sat, 19 Sep 2026 18:51:38 +0200 Subject: [PATCH] fix(dice): parse_dice validates sides >= _MIN_SIDES so d1/1d1 raise DiceParseError instead of leaking the model validator's pydantic ValidationError; drop the dead not-sides_str guard (regex \\d+ already guarantees non-empty) + 3 rejected-notation cases (d1, 1d1, 2D6) --- src/pf1e_simulator/dice.py | 4 +--- tests/test_dice.py | 3 +++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/pf1e_simulator/dice.py b/src/pf1e_simulator/dice.py index 5e45945..f33123b 100644 --- a/src/pf1e_simulator/dice.py +++ b/src/pf1e_simulator/dice.py @@ -103,15 +103,13 @@ def parse_dice(text: str) -> DiceExpr: m = _DICE_RE.match(stripped) if m: count_str, sides_str, bonus_str = m.groups() - if not sides_str: - raise DiceParseError(text) count = int(count_str) if count_str else 1 sides = int(sides_str) bonus = int(bonus_str) if bonus_str else 0 if count == 0: raise DiceParseError(text) - if sides < 1: + if sides < _MIN_SIDES: raise DiceParseError(text) return DiceExpr(count=count, sides=sides, bonus=bonus) diff --git a/tests/test_dice.py b/tests/test_dice.py index 0ffe400..4bca8b6 100644 --- a/tests/test_dice.py +++ b/tests/test_dice.py @@ -88,6 +88,9 @@ class TestParseDiceRejected: "d", "2d0", "0d6", + "d1", + "1d1", + "2D6", "2d 6", "abc", "d6+",