From f5db8d64828db756b80b6022322265a2b4f1c11b Mon Sep 17 00:00:00 2001 From: Rory Dudley Date: Sat, 6 Apr 2024 23:32:30 -0600 Subject: Capture STDOUT as bytes, and convert to string when necessary Previously, the recite() function created the 'out' variable, which was a String, that got passed to the various incant functions, in order to capture STDOUT in certain situations. In cases where STDOUT was captured, it was first converted to a String, and then appended to the 'out' variable, by means of String::from_utf8_lossy(). This works for basic text, however, does NOT work for binary data. This becomes problematic, when for example, downling a tar file with curl/wget, that is then piped ('|') to the tar program. Using from_utf8_lossy() in this case can corrupt the tar file. This patch makes it so that out is stored as bytes by default, and only converted to a String when necessary. --- src/poem/anthology/alias.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/poem/anthology/alias.rs') diff --git a/src/poem/anthology/alias.rs b/src/poem/anthology/alias.rs index 4c9b7b6..248342e 100644 --- a/src/poem/anthology/alias.rs +++ b/src/poem/anthology/alias.rs @@ -10,7 +10,7 @@ use std::collections::HashMap; /// ```sh /// alias vim=nvim /// ``` -pub fn incant(verse: &Verse, out: &mut String, aliases: &mut HashMap) -> i32 { +pub fn incant(verse: &Verse, out: &mut Vec, aliases: &mut HashMap) -> i32 { match verse.clause() { Some(clause) => { for stanza in clause { @@ -39,7 +39,7 @@ pub fn incant(verse: &Verse, out: &mut String, aliases: &mut HashMap