1
0
Fork 0

Fix splitting strings

Python does not specify how many _fields_ I want, but how many _splits_
to do.
master
LEdoian 5 years ago
parent 472dbda98a
commit 40a4e3ea11

@ -74,13 +74,13 @@ def parse_snippet(s: Tuple[str, str]) -> Sequence[Command]:
directory = parts[1] directory = parts[1]
continue continue
elif line.startswith('sudo -u'): elif line.startswith('sudo -u'):
parts = line.split(maxsplit=5) parts = line.split(maxsplit=4)
assert parts[3] == '-H', "Insecure sudo?" assert parts[3] == '-H', "Insecure sudo?"
user = parts[2] 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 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] cmd = parts[4]
elif line.startswith('sudo'): elif line.startswith('sudo'):
parts = line.split(maxsplit=2) parts = line.split(maxsplit=1)
assert not parts[1].startswith('-'), "Weird sudo" assert not parts[1].startswith('-'), "Weird sudo"
user = 'root' user = 'root'
cmd = parts[1] cmd = parts[1]
@ -141,7 +141,7 @@ def user_action(hunk: Sequence[Command], context=None) -> Sequence[Command]:
# Read the file back # Read the file back
new_hunk = [] new_hunk = []
for line in tmpfile.file.readlines(): 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)) 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 # Python has no goto for restarting, but we can recurse
return user_action(new_hunk, context) return user_action(new_hunk, context)

Loading…
Cancel
Save