From 4d345a59df513b40d30641e96d5cda357341eb67 Mon Sep 17 00:00:00 2001 From: JustAnotherArchivist Date: Fri, 20 Nov 2020 05:39:51 +0000 Subject: [PATCH] Fix splitting on various things other than LF causing exceptions in the grep output handling --- irclog.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/irclog.py b/irclog.py index 24eb05b..bcaa39e 100644 --- a/irclog.py +++ b/irclog.py @@ -935,7 +935,12 @@ class WebServer: # Process grep output with --with-filenames, --null, and --line-number into (path, line) tuples. # Lines are sorted by timestamp, filename, and line number to ensure a consistent and chronological order. out = [] - for line in stdout.decode('utf-8').splitlines(): + # splitlines splits on more than desired, in particular also on various things that can occur within IRC messages (which is really anything except CR LF, basically). + # split has the downside of producing a final empty element (because stdout ends with LF) and an empty element when the input is empty. + # So just discard empty lines. + for line in stdout.decode('utf-8').split('\n'): + if line == '': + continue fn, line = line.split('\0', 1) assert fn.startswith(self.config['storage']['path'] + '/') and fn.count('/', len(self.config['storage']['path']) + 1) == 1 _, path, _ = fn.rsplit('/', 2)