diff options
author | Rory Dudley | 2024-03-30 22:34:38 -0600 |
---|---|---|
committer | Rory Dudley | 2024-03-30 22:34:38 -0600 |
commit | 75872c78614abbdfec6b5fdd5ada1292d76fd5d8 (patch) | |
tree | 0c3d21b62752b447f5a8290e9740fd1de7ffc858 /src/poem | |
parent | b02576d3a00f182394be4bc41a26de50e4b64078 (diff) | |
download | dwarvish-75872c78614abbdfec6b5fdd5ada1292d76fd5d8.tar.gz |
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.
Notes
Notes:
This fix works for export (and alias), but could cause issues with other
builtins in the future. Worth keeping an eye on this, as this probably
isn't a perfect solution.
Diffstat (limited to 'src/poem')
-rw-r--r-- | src/poem/recite.rs | 9 |
1 files changed, 6 insertions, 3 deletions
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 { |