diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-07-24 11:09:23 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-07-24 11:09:23 -0400 |
commit | f3325cb39e9e20aa24d07107ebf048029059b44f (patch) | |
tree | b7c053bfdf81da5baf78758d0732c7e33af5460e /cmd2/utils.py | |
parent | 325e52451a81b900ac77626a2d2a271854544627 (diff) | |
download | cmd2-git-f3325cb39e9e20aa24d07107ebf048029059b44f.tar.gz |
Fixed a few commands that would have failed if arguments containing quotes were used
Diffstat (limited to 'cmd2/utils.py')
-rw-r--r-- | cmd2/utils.py | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/cmd2/utils.py b/cmd2/utils.py index b19c2b49..d0ce10bc 100644 --- a/cmd2/utils.py +++ b/cmd2/utils.py @@ -25,11 +25,8 @@ def is_quoted(arg: str) -> bool: return len(arg) > 1 and arg[0] == arg[-1] and arg[0] in constants.QUOTES -def quote_string_if_needed(arg: str) -> str: - """ Quotes a string if it contains spaces and isn't already quoted """ - if is_quoted(arg) or ' ' not in arg: - return arg - +def quote_string(arg: str) -> str: + """Quote a string""" if '"' in arg: quote = "'" else: @@ -38,8 +35,16 @@ def quote_string_if_needed(arg: str) -> str: return quote + arg + quote +def quote_string_if_needed(arg: str) -> str: + """Quote a string if it contains spaces and isn't already quoted""" + if is_quoted(arg) or ' ' not in arg: + return arg + + return quote_string(arg) + + def strip_quotes(arg: str) -> str: - """ Strip outer quotes from a string. + """Strip outer quotes from a string. Applies to both single and double quotes. |