Skip to content

Commit 2382d3f

Browse files
committed
fix: Narrowly quote %s argstrs with File/Directory traits
1 parent f6be432 commit 2382d3f

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

nipype/interfaces/base/core.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
from ...external.due import due
3434

35-
from .traits_extension import traits, isdefined, Undefined
35+
from .traits_extension import traits, isdefined, BasePath, Undefined
3636
from .specs import (
3737
BaseInterfaceInputSpec,
3838
CommandLineInputSpec,
@@ -798,6 +798,13 @@ def _format_arg(self, name, trait_spec, value):
798798
# type-checking code here as well
799799
sep = trait_spec.sep if trait_spec.sep is not None else " "
800800

801+
if argstr == '%s':
802+
inner_traits = getattr(trait_spec, "inner_traits", None)
803+
if inner_traits and any(
804+
t.is_trait_type(BasePath) for t in inner_traits
805+
):
806+
values = [shlex.quote(elt) for elt in value]
807+
801808
if argstr.endswith("..."):
802809
# repeatable option
803810
# --id %d... will expand to
@@ -807,6 +814,8 @@ def _format_arg(self, name, trait_spec, value):
807814
else:
808815
return argstr % sep.join(str(elt) for elt in value)
809816
else:
817+
if argstr == '%s' and trait_spec.is_trait_type(BasePath):
818+
return shlex.quote(value)
810819
# Append options using format string.
811820
return argstr % value
812821

0 commit comments

Comments
 (0)