Skip to content

Commit

Permalink
Merge pull request #117 from anweiss/116-validation-bug
Browse files Browse the repository at this point in the history
Fix type choice in array error collection logic
  • Loading branch information
anweiss authored Apr 15, 2022
2 parents b91f289 + 62c339a commit b8bb7e6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/validator/cbor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3484,7 +3484,7 @@ where
} else if !allow_empty_array {
self.add_error(format!("expected value {} at index {}", value, idx));
}
} else {
} else if !self.is_multi_type_choice {
self.add_error(format!("expected value {}, got {:?}", value, self.cbor));
}
}
Expand Down Expand Up @@ -3667,8 +3667,8 @@ mod tests {

let cddl = cddl.unwrap();

let mut jv = CBORValidator::new(&cddl, cbor, Some(&["cbor"]));
jv.validate()?;
let mut cv = CBORValidator::new(&cddl, cbor, Some(&["cbor"]));
cv.validate()?;

Ok(())
}
Expand Down
3 changes: 2 additions & 1 deletion src/validator/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ impl<'a> JSONValidator<'a> {
} else if !allow_empty_array {
self.add_error(format!("expected value {} at index {}", value, idx));
}
} else {
} else if !self.is_multi_type_choice {
self.add_error(format!("expected value {}, got {}", value, self.json));
}
}
Expand Down Expand Up @@ -643,6 +643,7 @@ impl<'a> Visitor<'a, Error> for JSONValidator<'a> {
// / integer ]), collect all errors and filter after the fact
if matches!(self.json, Value::Array(_)) {
let error_count = self.errors.len();

self.visit_type_choice(type_choice)?;

#[cfg(feature = "additional-controls")]
Expand Down

0 comments on commit b8bb7e6

Please sign in to comment.