From f72c68bab2d54775f717997ce782b81e000709e0 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Tue, 15 Dec 2020 13:10:13 -0800 Subject: [PATCH] Improve subproctools.quote. --- voussoirkit/subproctools.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/voussoirkit/subproctools.py b/voussoirkit/subproctools.py index feb328f..6f6ec6d 100644 --- a/voussoirkit/subproctools.py +++ b/voussoirkit/subproctools.py @@ -9,7 +9,8 @@ def quote(arg): # separate for external applications. # Ampersand, pipe, and caret are process flow and special escape. # Quotes inside quotes must be doubled up. - if arg == '' or any((c.isspace() or c in arg) for c in [',', ';', '=', '&', '|', '^', '"']): + badchars = [',', ';', '=', '&', '|', '^', '"'] + if arg == '' or any(c.isspace() for c in arg) or any(c in arg for c in badchars): arg = arg.replace('"', '""') arg = f'"{arg}"' return arg @@ -17,7 +18,8 @@ def quote(arg): # Semicolon is command delimiter. # Equals assigns shell variables. # Quotes inside quotes must be escaped with backslash. - if arg == '' or any((c.isspace() or c in arg) for c in [' ', ';', '=', '&', '|']): + badchars = [' ', ';', '=', '&', '|'] + if arg == '' or any(c.isspace() for c in arg) or any(c in arg for c in badchars): arg = arg.replace("'", "\\'") arg = f"'{arg}'" return arg