File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -317,8 +317,12 @@ def join(split_command):
317317 return ' ' .join (quote (arg ) for arg in split_command )
318318
319319
320- def quote (s ):
321- """Return a shell-escaped version of the string *s*."""
320+ def quote (s , force = False ):
321+ """Return a shell-escaped version of the string *s*.
322+
323+ If *force* is *True* then *s* will be quoted even if it is
324+ already safe for a shell without being quoted.
325+ """
322326 if not s :
323327 return "''"
324328
@@ -329,8 +333,11 @@ def quote(s):
329333 safe_chars = (b'%+,-./0123456789:=@'
330334 b'ABCDEFGHIJKLMNOPQRSTUVWXYZ_'
331335 b'abcdefghijklmnopqrstuvwxyz' )
332- # No quoting is needed if `s` is an ASCII string consisting only of `safe_chars`
333- if s .isascii () and not s .encode ().translate (None , delete = safe_chars ):
336+ if (not force
337+ and s .isascii () and not s .encode ().translate (None , delete = safe_chars )
338+ ):
339+ # No quoting is needed if we're not forcing quoting
340+ # and `s` is an ASCII string consisting only of `safe_chars`
334341 return s
335342
336343 # use single quotes, and put single quotes into double quotes
You can’t perform that action at this time.
0 commit comments