Skip to content

Commit

Permalink
fix: Ignore unknown keys in input
Browse files Browse the repository at this point in the history
This seems to be an input validation that even I forgot about, as in
README it says 'unknown fields are ignored' [1].

For now simply ignoring such fields should be enough to tackle the new
wwwauth[] key in Git 2.41.0 [2]. In the future if people complain that
these lines are not echoed back, we can consider adding a HashMap<String,
Vec<String>> field.

[1] https://github.com/Frederick888/git-credential-keepassxc/blob/5cb8047d6d9684d5c63081cc675fff850f6e221d/README.md?plain=1#L143
[2] git/git@af5388d...5f2117b
  • Loading branch information
Frederick888 committed Jun 2, 2023
1 parent 5cb8047 commit 57a7d9c
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,7 @@ macro_rules! message_from_to_string {
msg.$field_name = Some(pair[split_at + 1..].to_owned());
},
)*
_ => return Err(GitMessageParsingError {
message: format!("Unknown key {}", key),
source: s.to_owned(),
}),
_ => {},
}
}
Ok(msg)
Expand Down Expand Up @@ -198,4 +195,16 @@ mod tests {
message.set_string_fields(&advanced_fields);
assert_eq!(string1 + &string2 + "\n", message.to_string());
}

#[test]
fn test_03_ignore_unknown_fields() {
let string = "url=http://example.com\nfoo=bar\n".to_owned();
let message = GitCredentialMessage::from_str(string.as_str()).unwrap();
assert!(message.url.is_some());
assert_eq!(message.url.as_ref().unwrap().as_str(), "http://example.com");
assert_eq!(
"url=http://example.com\n\n".to_string(),
message.to_string()
);
}
}

0 comments on commit 57a7d9c

Please sign in to comment.