Skip to content

Commit

Permalink
fix validation of ints with leading unary plus (#1272)
Browse files Browse the repository at this point in the history
  • Loading branch information
cknv committed Apr 18, 2024
1 parent 4adf47f commit 91c3541
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/input/shared.rs
Expand Up @@ -114,6 +114,9 @@ fn clean_int_str(mut s: &str) -> Option<Cow<str>> {
// strip leading and trailing whitespace
s = s.trim();

// strip leading unary plus
s = s.strip_prefix('+').unwrap_or(s);

// strip loading zeros
s = strip_leading_zeros(s)?;

Expand Down
10 changes: 10 additions & 0 deletions tests/validators/test_int.py
Expand Up @@ -23,6 +23,10 @@
('00', 0),
('000', 0),
('0_000', 0),
('+0', 0),
('+00', 0),
('+000', 0),
('+0_000', 0),
(1, 1),
(' 1 ', 1),
(42, 42),
Expand All @@ -39,6 +43,12 @@
('00_', Err('Input should be a valid integer, unable to parse string as an integer')),
# next character after 9 is not valid
('0:', Err('Input should be a valid integer, unable to parse string as an integer')),
('+4_2', 42),
('+0_42', 42),
('+4_2.0', 42),
('+04_2.0', 42),
('++4_2', Err('Input should be a valid integer, unable to parse string as an integer')),
('+-1', Err('Input should be a valid integer, unable to parse string as an integer')),
('4_2', 42),
('0_42', 42),
('4_2.0', 42),
Expand Down

0 comments on commit 91c3541

Please sign in to comment.