Skip to content

Commit 91c3541

Browse files
authored
fix validation of ints with leading unary plus (#1272)
1 parent 4adf47f commit 91c3541

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/input/shared.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ fn clean_int_str(mut s: &str) -> Option<Cow<str>> {
114114
// strip leading and trailing whitespace
115115
s = s.trim();
116116

117+
// strip leading unary plus
118+
s = s.strip_prefix('+').unwrap_or(s);
119+
117120
// strip loading zeros
118121
s = strip_leading_zeros(s)?;
119122

tests/validators/test_int.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
('00', 0),
2424
('000', 0),
2525
('0_000', 0),
26+
('+0', 0),
27+
('+00', 0),
28+
('+000', 0),
29+
('+0_000', 0),
2630
(1, 1),
2731
(' 1 ', 1),
2832
(42, 42),
@@ -39,6 +43,12 @@
3943
('00_', Err('Input should be a valid integer, unable to parse string as an integer')),
4044
# next character after 9 is not valid
4145
('0:', Err('Input should be a valid integer, unable to parse string as an integer')),
46+
('+4_2', 42),
47+
('+0_42', 42),
48+
('+4_2.0', 42),
49+
('+04_2.0', 42),
50+
('++4_2', Err('Input should be a valid integer, unable to parse string as an integer')),
51+
('+-1', Err('Input should be a valid integer, unable to parse string as an integer')),
4252
('4_2', 42),
4353
('0_42', 42),
4454
('4_2.0', 42),

0 commit comments

Comments
 (0)