From 2a277eed6a742febec7cbffcd8a1fde0393efae2 Mon Sep 17 00:00:00 2001 From: Nathaniel Filardo Date: Wed, 21 Nov 2018 15:17:50 +0000 Subject: [PATCH] main: filter_output loses line prefixes If the watched process ends a push to the pipe without a newline at the end, but with newlines in the middle, then sep_rx.split() will return with multiple entries, the last of which will not end with a newline and yet not be the empty string. This line prefix needs to be stashed into the pending buffer, too. This turns out to be exactly the same logic as if sep_rx.split had not split the string, so eliminate one layer of conditionals. This version incorporates feedback from Rob Browning to continue to pass a list to extend(). Signed-off-by: Nathaniel Filardo --- main.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/main.py b/main.py index c0679e329..5bdbf4b56 100755 --- a/main.py +++ b/main.py @@ -204,16 +204,15 @@ def filter_output(src_out, src_err, dest_out, dest_err): print_clean_line(dest, pending.pop(fd, []), width) else: split = sep_rx.split(buf) - if len(split) > 2: - while len(split) > 1: - content, sep = split[:2] - split = split[2:] - print_clean_line(dest, - pending.pop(fd, []) + [content], - width, - sep) - else: - assert(len(split) == 1) + while len(split) > 1: + content, sep = split[:2] + split = split[2:] + print_clean_line(dest, + pending.pop(fd, []) + [content], + width, + sep) + assert(len(split) == 1) + if split[0] : pending.setdefault(fd, []).extend(split) except BaseException as ex: pending_ex = chain_ex(add_ex_tb(ex), pending_ex)