diff --git a/lib/python/base_cli/history.py b/lib/python/base_cli/history.py index 675b697..04ccd2e 100644 --- a/lib/python/base_cli/history.py +++ b/lib/python/base_cli/history.py @@ -262,7 +262,7 @@ def display_command(cli_name: str, argv: list[str]) -> str: def parse_positive_int(option: str, value: str) -> int: - if not value.isdigit(): + if not value.isdecimal(): raise ValueError(f"Option '{option}' must be a positive integer.") amount = int(value) if amount <= 0: diff --git a/tests/test_history.py b/tests/test_history.py index 7a2863f..0289642 100644 --- a/tests/test_history.py +++ b/tests/test_history.py @@ -58,6 +58,15 @@ def test_msvcrt_backend_uses_a_private_sidecar_lock(self) -> None: self.assertEqual(fake_msvcrt.calls, [(_FakeMsvcrt.LK_LOCK, 1), (_FakeMsvcrt.LK_UNLCK, 1)]) + +class PositiveIntegerTests(unittest.TestCase): + def test_parse_positive_int_rejects_digit_like_non_decimal_characters(self) -> None: + with self.assertRaisesRegex(ValueError, "Option '--limit' must be a positive integer"): + history.parse_positive_int("--limit", "²") + + def test_parse_positive_int_accepts_decimal_digits(self) -> None: + self.assertEqual(history.parse_positive_int("--limit", "١٢"), 12) + def test_msvcrt_sidecar_initialization_race_is_tolerated(self) -> None: fake_msvcrt = _FakeMsvcrt() original_write = history.os.write