Skip to content

Commit

Permalink
fix: V3 message binary content was not being base64 decoded correctly…
Browse files Browse the repository at this point in the history
… when loaded from a Pact file
  • Loading branch information
rholshausen committed Aug 4, 2023
1 parent ee7a45d commit a03fc5f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 31 deletions.
54 changes: 27 additions & 27 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 11 additions & 4 deletions rust/pact_models/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl Message {
/// Constructs a `Message` from the `Json` struct.
pub fn from_json(index: usize, json: &Value, spec_version: &PactSpecification) -> anyhow::Result<Message> {
match spec_version {
&PactSpecification::V3 => {
PactSpecification::V3 => {
let id = json.get("_id").map(|id| json_to_string(id));
let description = match json.get("description") {
Some(v) => match *v {
Expand All @@ -200,7 +200,6 @@ impl Message {
}).collect(),
_ => hashmap!{},
};
let mut body = body_from_json(json, "contents", &None);
let content_type = metadata.iter()
.find(|(k, _)| {
let key = k.to_ascii_lowercase();
Expand All @@ -209,9 +208,17 @@ impl Message {
.map(|(_, v)| json_to_string(v))
.map(|s| ContentType::parse(s.as_str()).ok())
.flatten();
if let Some(ct) = content_type {

let body = if let Some(ct) = content_type {
let mut body = body_from_json(json, "contents", &Some(hashmap!{
"content-type".to_string() => vec![ ct.to_string() ]
}));
body.set_content_type(&ct);
}
body
} else {
body_from_json(json, "contents", &None)
};

Ok(Message {
id,
description,
Expand Down

0 comments on commit a03fc5f

Please sign in to comment.