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)
This commit is contained in:
@@ -103,15 +103,13 @@ def parse_dice(text: str) -> DiceExpr:
|
|||||||
m = _DICE_RE.match(stripped)
|
m = _DICE_RE.match(stripped)
|
||||||
if m:
|
if m:
|
||||||
count_str, sides_str, bonus_str = m.groups()
|
count_str, sides_str, bonus_str = m.groups()
|
||||||
if not sides_str:
|
|
||||||
raise DiceParseError(text)
|
|
||||||
count = int(count_str) if count_str else 1
|
count = int(count_str) if count_str else 1
|
||||||
sides = int(sides_str)
|
sides = int(sides_str)
|
||||||
bonus = int(bonus_str) if bonus_str else 0
|
bonus = int(bonus_str) if bonus_str else 0
|
||||||
|
|
||||||
if count == 0:
|
if count == 0:
|
||||||
raise DiceParseError(text)
|
raise DiceParseError(text)
|
||||||
if sides < 1:
|
if sides < _MIN_SIDES:
|
||||||
raise DiceParseError(text)
|
raise DiceParseError(text)
|
||||||
|
|
||||||
return DiceExpr(count=count, sides=sides, bonus=bonus)
|
return DiceExpr(count=count, sides=sides, bonus=bonus)
|
||||||
|
|||||||
@@ -88,6 +88,9 @@ class TestParseDiceRejected:
|
|||||||
"d",
|
"d",
|
||||||
"2d0",
|
"2d0",
|
||||||
"0d6",
|
"0d6",
|
||||||
|
"d1",
|
||||||
|
"1d1",
|
||||||
|
"2D6",
|
||||||
"2d 6",
|
"2d 6",
|
||||||
"abc",
|
"abc",
|
||||||
"d6+",
|
"d6+",
|
||||||
|
|||||||
Reference in New Issue
Block a user