From 75872c78614abbdfec6b5fdd5ada1292d76fd5d8 Mon Sep 17 00:00:00 2001 From: Rory Dudley Date: Sat, 30 Mar 2024 22:34:38 -0600 Subject: Fix a subtle bug when running interal poems This patch fixes a bug for internal poems, where the output would always get split on newlines, regardless of the verse's verb. This breaks things like 'export DIR=`ls`', since output from `ls` might have newlines, meaning that $DIR will only contains the first item from the `ls` command. This will only perform the newline split when sending the output to a non-builtin command. --- src/poem/recite.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/poem/recite.rs') diff --git a/src/poem/recite.rs b/src/poem/recite.rs index 9a425e8..a067f3d 100644 --- a/src/poem/recite.rs +++ b/src/poem/recite.rs @@ -66,6 +66,9 @@ impl Reciteable for Poem { None => {} }; + // Check if verse is a builtin + let index = anthology::lookup(&verse.verb()); + // Run interal poems let v = verse.clone(); let mut new_stanza = None; @@ -98,7 +101,7 @@ impl Reciteable for Poem { None => break, // TODO: Return an error }; let out = poem.recite(env, Some(false))?; - if out.contains("\n") { + if out.contains("\n") && index.is_none() { let mut out = out.split("\n"); let next = out.next().unwrap_or("").trim(); *wordp = wordp.replacen("\x0b", next, 1).to_string(); @@ -118,6 +121,7 @@ impl Reciteable for Poem { } else { *wordp = wordp.replacen("\x0b", out.as_str(), 1).to_string(); } + *wordp = wordp.replacen("\x0b", out.as_str(), 1).to_string(); } j += 1; } @@ -129,10 +133,9 @@ impl Reciteable for Poem { verse.stanza.append(&mut stanza); } None => {} - } + }; // Incant the verse if it's a built-in - let index = anthology::lookup(&verse.verb()); let status = if index.is_some() { anthology::incant(&verse, index.unwrap(), env) } else { -- cgit v1.2.3