1
1
"""Implementation of CommandLineTool."""
2
2
3
3
import copy
4
+ from enum import Enum
4
5
import hashlib
5
6
import json
6
7
import locale
22
23
MutableMapping ,
23
24
MutableSequence ,
24
25
Optional ,
26
+ Pattern ,
25
27
Set ,
26
28
TextIO ,
27
29
Union ,
84
86
if TYPE_CHECKING :
85
87
from .provenance_profile import ProvenanceProfile # pylint: disable=unused-import
86
88
87
- ACCEPTLIST_EN_STRICT_RE = re .compile (
88
- r"^[\w.+\-\u2600-\u26FF\U0001f600-\U0001f64f]+$"
89
- ) # accept unicode word characters and emojis
90
- ACCEPTLIST_EN_RELAXED_RE = re .compile (r".*" ) # Accept anything
91
- ACCEPTLIST_RE = ACCEPTLIST_EN_STRICT_RE
89
+
90
+ class PathCheckingMode (Enum ):
91
+ """What characters are allowed in path names.
92
+
93
+ We have the strict, default mode and the relaxed mode.
94
+ """
95
+
96
+ STRICT = re .compile (
97
+ r"^[\w.+\-\u2600-\u26FF\U0001f600-\U0001f64f]+$"
98
+ ) # accept unicode word characters and emojis
99
+ RELAXED = re .compile (r".*" ) # Accept anything
100
+
101
+
92
102
DEFAULT_CONTAINER_MSG = """
93
103
We are on Microsoft Windows and not all components of this CWL description have a
94
104
container specified. This means that these steps will be executed in the default container,
@@ -301,7 +311,9 @@ def run(
301
311
)
302
312
303
313
304
- def check_adjust (builder : Builder , file_o : CWLObjectType ) -> CWLObjectType :
314
+ def check_adjust (
315
+ accept_re : Pattern [str ], builder : Builder , file_o : CWLObjectType
316
+ ) -> CWLObjectType :
305
317
"""
306
318
Map files to assigned path inside a container.
307
319
@@ -327,7 +339,7 @@ def check_adjust(builder: Builder, file_o: CWLObjectType) -> CWLObjectType:
327
339
file_o ["nameroot" ] = str (nr )
328
340
if file_o .get ("nameext" ) != ne :
329
341
file_o ["nameext" ] = str (ne )
330
- if not ACCEPTLIST_RE .match (basename ):
342
+ if not accept_re .match (basename ):
331
343
raise WorkflowException (
332
344
"Invalid filename: '{}' contains illegal characters" .format (
333
345
file_o ["basename" ]
@@ -368,6 +380,11 @@ def __init__(
368
380
"""Initialize this CommandLineTool."""
369
381
super ().__init__ (toolpath_object , loadingContext )
370
382
self .prov_obj = loadingContext .prov_obj
383
+ self .path_check_mode = (
384
+ PathCheckingMode .RELAXED
385
+ if loadingContext .relax_path_checks
386
+ else PathCheckingMode .STRICT
387
+ ) # type: PathCheckingMode
371
388
372
389
def make_job_runner (self , runtimeContext : RuntimeContext ) -> Type [JobBase ]:
373
390
dockerReq , dockerRequired = self .get_requirement ("DockerRequirement" )
@@ -685,7 +702,7 @@ def remove_dirname(d: CWLObjectType) -> None:
685
702
visit_class (
686
703
[builder .files , builder .bindings ],
687
704
("File" , "Directory" ),
688
- partial (check_adjust , builder ),
705
+ partial (check_adjust , self . path_check_mode . value , builder ),
689
706
)
690
707
691
708
def job (
@@ -713,7 +730,9 @@ def job(
713
730
cachebuilder .stagedir ,
714
731
separateDirs = False ,
715
732
)
716
- _check_adjust = partial (check_adjust , cachebuilder )
733
+ _check_adjust = partial (
734
+ check_adjust , self .path_check_mode .value , cachebuilder
735
+ )
717
736
visit_class (
718
737
[cachebuilder .files , cachebuilder .bindings ],
719
738
("File" , "Directory" ),
@@ -887,7 +906,7 @@ def update_status_output_callback(
887
906
)
888
907
builder .requirements = j .requirements
889
908
890
- _check_adjust = partial (check_adjust , builder )
909
+ _check_adjust = partial (check_adjust , self . path_check_mode . value , builder )
891
910
892
911
visit_class (
893
912
[builder .files , builder .bindings ], ("File" , "Directory" ), _check_adjust
0 commit comments