From 5d95f10dd8e3b3c55d0200348020c3f56787b3ab Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Sun, 26 Nov 2017 14:02:59 -0500 Subject: [PATCH] remove trailing newline from sub-shell strings. --- mpw-shell-expand.rl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mpw-shell-expand.rl b/mpw-shell-expand.rl index 04bcc17..d67f8b5 100644 --- a/mpw-shell-expand.rl +++ b/mpw-shell-expand.rl @@ -157,6 +157,14 @@ std::string subshell(const std::string &s, Environment &env, const fdmask &fds) } tmp.append(buffer, buffer + len); } + + + /* if present, a trailing carriage return is stripped */ + + if (!tmp.empty()) { + if (tmp.back() == '\r' || tmp.back() == '\n') tmp.pop_back(); + } + std::transform(tmp.begin(), tmp.end(), tmp.begin(), [](uint8_t x){ if (x == '\r' || x == '\n') x = ' '; return x;