From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stefano Brivio To: passt-dev@passt.top Subject: [PATCH 06/12] tests: Improve control character filtering in pane_parse Date: Tue, 17 May 2022 14:36:08 +0200 Message-ID: <20220517123614.1892316-7-sbrivio@redhat.com> In-Reply-To: <20220517123614.1892316-1-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============5209055460628991732==" --===============5209055460628991732== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: David Gibson 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 [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 --- test/lib/term | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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=3D"$(echo "${1}" | tr [A-Z] [a-z])" =20 - __buf=3D"$(tail -n2 ${LOGDIR}/pane_${__pane_lc}.log | head -n1 | tr -d -c [= :print:])" + __buf=3D"$(tail -n2 ${LOGDIR}/pane_${__pane_lc}.log | head -n1 | sed 's/^[^= \r]*\r\([^\r]\)/\1/' | tr -d '\r\n')" =20 [ "# $(eval printf '%s' \"\$${1}_LAST_CMD\")" !=3D "${__buf}" ] && \ [ "$ $(eval printf '%s' \"\$${1}_LAST_CMD\")" !=3D "${__buf}" ] && --=20 2.35.1 --===============5209055460628991732==--