Skip to content

Commit 4433435

Browse files
committed
rust set length checks
1 parent b818f74 commit 4433435

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/input/return_enums.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -176,22 +176,30 @@ fn validate_iter_to_set<'a, 's>(
176176
recursion_guard: &'s mut RecursionGuard,
177177
) -> ValResult<'a, ()> {
178178
let mut errors: Vec<ValLineError> = Vec::new();
179+
let mut spaces_left = max_length.unwrap_or(0);
179180
for (index, item_result) in iter.enumerate() {
180181
let item = item_result.map_err(|e| any_next_error!(py, e, input, index))?;
181182
match validator.validate(py, item, extra, definitions, recursion_guard) {
182183
Ok(item) => {
183184
set.build_add(item)?;
184185
if let Some(max_length) = max_length {
185-
let actual_length = set.build_len();
186-
if actual_length > max_length {
187-
return Err(ValError::new(
188-
ErrorType::TooLong {
189-
field_type: field_type.to_string(),
190-
max_length,
191-
actual_length,
192-
},
193-
input,
194-
));
186+
match spaces_left.checked_sub(1) {
187+
Some(spaces) => spaces_left = spaces,
188+
None => {
189+
let actual_length = set.build_len();
190+
if actual_length > max_length {
191+
return Err(ValError::new(
192+
ErrorType::TooLong {
193+
field_type: field_type.to_string(),
194+
max_length,
195+
actual_length,
196+
},
197+
input,
198+
));
199+
} else {
200+
spaces_left = max_length - actual_length;
201+
}
202+
}
195203
}
196204
}
197205
}

0 commit comments

Comments
 (0)