diff options
author | David Gibson <david@gibson.dropbear.id.au> | 2022-05-12 15:12:05 +1000 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2022-05-19 15:24:15 +0200 |
commit | c638129a9e803388a37d95c4c411047571556109 (patch) | |
tree | a3a35a8a27c38cd050f1686d05c7f9f2b0f93fe8 | |
parent | ae83999b75165669ba468defa4cddced3ef2b058 (diff) | |
download | passt-c638129a9e803388a37d95c4c411047571556109.tar passt-c638129a9e803388a37d95c4c411047571556109.tar.gz passt-c638129a9e803388a37d95c4c411047571556109.tar.bz2 passt-c638129a9e803388a37d95c4c411047571556109.tar.lz passt-c638129a9e803388a37d95c4c411047571556109.tar.xz passt-c638129a9e803388a37d95c4c411047571556109.tar.zst passt-c638129a9e803388a37d95c4c411047571556109.zip |
tests: Improve control character filtering in pane_parse
pane_parse() attempts to grab the output from the last command issued
into a tmux pane. It strips out control characters using tr, which in
particular includes the final \r\n. However, this won't fully strip
out terminal escape sequences. In particular this breaks if the shell
in the pane is bash, with enable-bracketed-paste enabled in readline.
That issues terminal sequences to enable and disable bracketed paste
mode around every shell prompt.
We can work around this because these escapes are followed by a \r
(CR). More generally, it seems reasonable to assume that any terminal
shenanigans followed by a CR, but not an LF is supposed to be hidden.
So, use sed to strip everything before the second last CR. We still
need the tr to remove the final \r\n from the string (sed processes a
line at a time, and doesn't consider the CRLF part of the buffer it's
processing).
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
[sbrivio: modify regexp to keep foo\r\r\n unchanged, by matching on at
least one CR and a non-CR afterwards: that's the usual output pattern
for bash on Debian 8 and Debian 9]
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
-rwxr-xr-x | test/lib/term | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/test/lib/term b/test/lib/term index 7dd9826..0093f90 100755 --- a/test/lib/term +++ b/test/lib/term @@ -221,7 +221,7 @@ pane_wait() { pane_parse() { __pane_lc="$(echo "${1}" | tr [A-Z] [a-z])" - __buf="$(tail -n2 ${LOGDIR}/pane_${__pane_lc}.log | head -n1 | tr -d -c [:print:])" + __buf="$(tail -n2 ${LOGDIR}/pane_${__pane_lc}.log | head -n1 | sed 's/^[^\r]*\r\([^\r]\)/\1/' | tr -d '\r\n')" [ "# $(eval printf '%s' \"\$${1}_LAST_CMD\")" != "${__buf}" ] && \ [ "$ $(eval printf '%s' \"\$${1}_LAST_CMD\")" != "${__buf}" ] && |