From 40a4e3ea11f0839900f8307d193d4fc3ca7d54fd Mon Sep 17 00:00:00 2001 From: Pavel 'LEdoian' Turinsky Date: Mon, 4 May 2020 19:02:05 +0200 Subject: [PATCH] Fix splitting strings Python does not specify how many _fields_ I want, but how many _splits_ to do. --- markdownrunner.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/markdownrunner.py b/markdownrunner.py index 8f040ee..1a8a114 100755 --- a/markdownrunner.py +++ b/markdownrunner.py @@ -74,13 +74,13 @@ def parse_snippet(s: Tuple[str, str]) -> Sequence[Command]: directory = parts[1] continue elif line.startswith('sudo -u'): - parts = line.split(maxsplit=5) + parts = line.split(maxsplit=4) assert parts[3] == '-H', "Insecure sudo?" user = parts[2] directory = f'~{user}' # This actually works with SSH. That is nice, since we don't need to know the target's /etc/passwd cmd = parts[4] elif line.startswith('sudo'): - parts = line.split(maxsplit=2) + parts = line.split(maxsplit=1) assert not parts[1].startswith('-'), "Weird sudo" user = 'root' cmd = parts[1] @@ -141,7 +141,7 @@ def user_action(hunk: Sequence[Command], context=None) -> Sequence[Command]: # Read the file back new_hunk = [] for line in tmpfile.file.readlines(): - parts = line.split('\t', maxsplit=3) + parts = line.split('\t', maxsplit=2) new_hunk.append(Command(user=parts[0],directory=parts[1],command=parts[2],context=None)) # Python has no goto for restarting, but we can recurse return user_action(new_hunk, context)