Skip to content

Commit

Permalink
validator: if contentEncoding fails, skip contentMediaType
Browse files Browse the repository at this point in the history
  • Loading branch information
santhosh-tekuri committed Apr 10, 2024
1 parent a932bca commit 75b242a
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,20 +479,23 @@ impl<'v, 's, 'd, 'e> Validator<'v, 's, 'd, 'e> {
}

// contentEncoding --
let mut decoded = Cow::from(str.as_bytes());
let mut decoded = Some(Cow::from(str.as_bytes()));
if let Some(decoder) = &s.content_encoding {
match (decoder.func)(str) {
Ok(bytes) => decoded = Cow::from(bytes),
Err(err) => self.add_error(ErrorKind::ContentEncoding {
want: decoder.name,
err,
}),
Ok(bytes) => decoded = Some(Cow::from(bytes)),
Err(err) => {
decoded = None;
self.add_error(ErrorKind::ContentEncoding {
want: decoder.name,
err,
})
}
}
}

// contentMediaType --
let mut deserialized = None;
if let Some(mt) = &s.content_media_type {
if let (Some(mt), Some(decoded)) = (&s.content_media_type, decoded) {
match (mt.func)(decoded.as_ref(), s.content_schema.is_some()) {
Ok(des) => deserialized = des,
Err(e) => {
Expand Down

0 comments on commit 75b242a

Please sign in to comment.