Skip to content

Commit

Permalink
fix by only running nested if outer is not run
Browse files Browse the repository at this point in the history
  • Loading branch information
pvichivanives committed Dec 16, 2024
1 parent 2f24331 commit 83c21a7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## Changelog

## 0.19.1 (unreleased)

- Bug fix for nested issue with custom only running nested if outer passes


## 0.19.0 (2024/11/03)

- Swap to using proc-macro-error-2 instead of proc-macro-error for Syn
Expand Down
5 changes: 3 additions & 2 deletions validator/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,10 @@ impl ValidationErrors {
fn add_nested(&mut self, field: &'static str, errors: ValidationErrorsKind) {
if let Vacant(entry) = self.0.entry(field) {
entry.insert(errors);
} else {
panic!("Attempt to replace non-empty ValidationErrors entry");
}
// Else case here is simply do nothing. Pretty sure this is caught earlier to not run but since
// If we get here, just not adding it does the same thing (although waste extra compute)
// probably better to just ignore here.
}

#[must_use]
Expand Down
4 changes: 3 additions & 1 deletion validator_derive/src/tokens/nested.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ pub fn nested_tokens(
field_name_str: &str,
) -> proc_macro2::TokenStream {
quote! {
errors.merge_self(#field_name_str, (&#field_name).validate());
if let std::collections::hash_map::Entry::Vacant(entry) = errors.0.entry(#field_name_str) {
errors.merge_self(#field_name_str, (&#field_name).validate());
}
}
}

0 comments on commit 83c21a7

Please sign in to comment.