mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2025-01-05 17:15:19 +03:00
Merge pull request #3863 from gitbutlerapp/escape-trailer-newline
feat: Add support for trailers with newlines
This commit is contained in:
commit
d96e5cda80
@ -209,7 +209,8 @@ pub struct Trailer {
|
||||
|
||||
impl Display for Trailer {
|
||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||
write!(f, "{}: {}", self.key, self.value)
|
||||
let escaped_value = self.value.replace('\n', "\\n");
|
||||
write!(f, "{}: {}", self.key, escaped_value)
|
||||
}
|
||||
}
|
||||
|
||||
@ -220,9 +221,10 @@ impl FromStr for Trailer {
|
||||
if parts.len() != 2 {
|
||||
return Err(anyhow!("Invalid trailer format"));
|
||||
}
|
||||
let unescaped_value = parts[1].trim().replace("\\n", "\n");
|
||||
Ok(Self {
|
||||
key: parts[0].trim().to_string(),
|
||||
value: parts[1].trim().to_string(),
|
||||
value: unescaped_value,
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -333,4 +335,21 @@ mod tests {
|
||||
);
|
||||
assert_eq!(details.to_string(), commit_message);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_create_snapshot_containing_trailer_with_newline() {
|
||||
let snapshot_details = SnapshotDetails {
|
||||
version: Version(1),
|
||||
operation: OperationType::CreateCommit,
|
||||
title: "Create a new snapshot".to_string(),
|
||||
body: None,
|
||||
trailers: vec![Trailer {
|
||||
key: "Message".to_string(),
|
||||
value: "Header\n\nBody".to_string(),
|
||||
}],
|
||||
};
|
||||
let serialized = snapshot_details.to_string();
|
||||
let deserialized = SnapshotDetails::from_str(&serialized).unwrap();
|
||||
assert_eq!(deserialized, snapshot_details)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user