|
1 |
| -from pathlib import Path |
2 |
| - |
3 | 1 | import pytest
|
| 2 | +import urllib.parse |
4 | 3 |
|
5 |
| -from cwltool.main import main |
| 4 | +from pathlib import Path |
| 5 | +from typing import cast |
| 6 | +from ruamel.yaml.comments import CommentedMap |
| 7 | +from schema_salad.sourceline import cmap |
6 | 8 |
|
| 9 | +from cwltool.main import main |
| 10 | +from cwltool.command_line_tool import CommandLineTool |
| 11 | +from cwltool.context import LoadingContext, RuntimeContext |
| 12 | +from cwltool.update import INTERNAL_VERSION |
| 13 | +from cwltool.utils import CWLObjectType |
7 | 14 | from .util import needs_docker
|
8 | 15 |
|
| 16 | + |
9 | 17 | script = """
|
10 | 18 | #!/usr/bin/env cwl-runner
|
11 | 19 | cwlVersion: v1.0
|
@@ -95,3 +103,67 @@ def test_unicode_in_output_files(tmp_path: Path, filename: str) -> None:
|
95 | 103 | filename,
|
96 | 104 | ]
|
97 | 105 | assert main(params) == 0
|
| 106 | + |
| 107 | + |
| 108 | +def test_clt_returns_specialchar_names(tmp_path: Path) -> None: |
| 109 | + """Confirm that special characters in filenames do not cause problems.""" |
| 110 | + loading_context = LoadingContext( |
| 111 | + { |
| 112 | + "metadata": { |
| 113 | + "cwlVersion": INTERNAL_VERSION, |
| 114 | + "http://commonwl.org/cwltool#original_cwlVersion": INTERNAL_VERSION, |
| 115 | + } |
| 116 | + } |
| 117 | + ) |
| 118 | + clt = CommandLineTool( |
| 119 | + cast( |
| 120 | + CommentedMap, |
| 121 | + cmap( |
| 122 | + { |
| 123 | + "cwlVersion": INTERNAL_VERSION, |
| 124 | + "class": "CommandLineTool", |
| 125 | + "inputs": [], |
| 126 | + "outputs": [], |
| 127 | + "requirements": [], |
| 128 | + } |
| 129 | + ), |
| 130 | + ), |
| 131 | + loading_context, |
| 132 | + ) |
| 133 | + |
| 134 | + # Reserved characters will be URL encoded during the creation of a file URI |
| 135 | + # Internal references to files are in URI form, and are therefore URL encoded |
| 136 | + # Final output files should not retain their URL encoded filenames |
| 137 | + rfc_3986_gen_delims = [":", "/", "?", "#", "[", "]", "@"] |
| 138 | + rfc_3986_sub_delims = ["!", "$", "&", "'", "(", ")", "*", "+", ",", ";", "="] |
| 139 | + unix_reserved = ["/", "\0"] |
| 140 | + reserved = [ |
| 141 | + special_char |
| 142 | + for special_char in (rfc_3986_gen_delims + rfc_3986_sub_delims) |
| 143 | + if special_char not in unix_reserved |
| 144 | + ] |
| 145 | + |
| 146 | + # Mock an "output" file with the above special characters in its name |
| 147 | + special = "".join(reserved) |
| 148 | + output_schema = cast( |
| 149 | + CWLObjectType, {"type": "File", "outputBinding": {"glob": special}} |
| 150 | + ) |
| 151 | + mock_output = tmp_path / special |
| 152 | + mock_output.touch() |
| 153 | + |
| 154 | + # Prepare minimal arguments for CommandLineTool.collect_output() |
| 155 | + builder = clt._init_job({}, RuntimeContext()) |
| 156 | + builder.pathmapper = clt.make_path_mapper( |
| 157 | + builder.files, builder.stagedir, RuntimeContext(), True |
| 158 | + ) |
| 159 | + fs_access = builder.make_fs_access(str(tmp_path)) |
| 160 | + |
| 161 | + result = cast( |
| 162 | + CWLObjectType, |
| 163 | + clt.collect_output(output_schema, builder, str(tmp_path), fs_access), |
| 164 | + ) |
| 165 | + |
| 166 | + assert result["class"] == "File" |
| 167 | + assert result["basename"] == special |
| 168 | + assert result["nameroot"] == special |
| 169 | + assert str(result["location"]).endswith(urllib.parse.quote(special)) |
0 commit comments