Skip to content

Commit efc0702

Browse files
authored
Merge pull request #3417 from qian587/fix-3416
[FIX] Escape metacharacters when parsing dcm2niix outputs
2 parents ee50279 + 09ff390 commit efc0702

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

.zenodo.json

+3
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,9 @@
860860
"affiliation": "MIT, HMS",
861861
"name": "Ghosh, Satrajit",
862862
"orcid": "0000-0002-5312-6729"
863+
},
864+
{
865+
"name": "Hui Qian, Tan"
863866
}
864867
],
865868
"keywords": [

nipype/interfaces/dcm2nii.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import re
55
from copy import deepcopy
66
import itertools as it
7+
import glob
78
from glob import iglob
89

910
from ..utils.filemanip import split_filename
@@ -494,4 +495,6 @@ def _list_outputs(self):
494495

495496
# https://stackoverflow.com/a/4829130
496497
def search_files(prefix, outtypes):
497-
return it.chain.from_iterable(iglob(prefix + outtype) for outtype in outtypes)
498+
return it.chain.from_iterable(
499+
iglob(glob.escape(prefix + outtype)) for outtype in outtypes
500+
)
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import pytest
2+
3+
4+
from nipype.interfaces import dcm2nii
5+
6+
7+
@pytest.mark.parametrize(
8+
"fname, extension",
9+
[
10+
("output_1", ".txt"),
11+
("output_w_[]_meta_1", ".json"),
12+
("output_w_**^$?_meta_2", ".txt"),
13+
],
14+
)
15+
def test_search_files(tmp_path, fname, extension):
16+
tmp_fname = fname + extension
17+
test_file = tmp_path / tmp_fname
18+
test_file.touch()
19+
actual_files_list = dcm2nii.search_files(str(tmp_path / fname), [extension])
20+
for f in actual_files_list:
21+
assert str(test_file) == f

0 commit comments

Comments
 (0)