@@ -270,6 +270,11 @@ class DockerBuildCommand(BuildCommand):
270
270
Build command to execute in docker container
271
271
"""
272
272
273
+ bash_escape_re = re .compile (
274
+ r"([\t\ \!\"\#\$\&\'\(\)\*\:\;\<\>\?\@"
275
+ r'\[\\\]\^\`\{\|\}\~])'
276
+ )
277
+
273
278
def __init__ (self , * args , escape_command = True , ** kwargs ):
274
279
"""
275
280
Override default to extend behavior.
@@ -345,19 +350,16 @@ def get_wrapped_command(self):
345
350
``escape_command=True`` in the init method this escapes a good majority
346
351
of those characters.
347
352
"""
348
- bash_escape_re = re .compile (
349
- r"([\t\ \!\"\#\$\&\'\(\)\*\:\;\<\>\?\@"
350
- r'\[\\\]\^\`\{\|\}\~])' ,
351
- )
352
353
prefix = ''
353
354
if self .bin_path :
354
- prefix += 'PATH={}:$PATH ' .format (self .bin_path )
355
+ bin_path = self ._escape_command (self .bin_path )
356
+ prefix += f'PATH={ bin_path } :$PATH '
355
357
356
358
command = (
357
- ' ' .join ([
358
- bash_escape_re . sub ( r'\\\1' , part ) if self .escape_command else part
359
+ ' ' .join (
360
+ self . _escape_command ( part ) if self .escape_command else part
359
361
for part in self .command
360
- ] )
362
+ )
361
363
)
362
364
return (
363
365
"/bin/sh -c '{prefix}{cmd}'" .format (
@@ -366,6 +368,10 @@ def get_wrapped_command(self):
366
368
)
367
369
)
368
370
371
+ def _escape_command (self , cmd ):
372
+ r"""Escape the command by prefixing suspicious chars with `\`."""
373
+ return self .bash_escape_re .sub (r'\\\1' , cmd )
374
+
369
375
370
376
class BaseEnvironment :
371
377
0 commit comments