Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Escape metacharacters when parsing dcm2niix outputs #3417

Merged
merged 4 commits into from
Dec 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .zenodo.json
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,9 @@
"affiliation": "MIT, HMS",
"name": "Ghosh, Satrajit",
"orcid": "0000-0002-5312-6729"
},
{
"name": "Hui Qian, Tan"
}
],
"keywords": [
Expand Down
5 changes: 4 additions & 1 deletion nipype/interfaces/dcm2nii.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import re
from copy import deepcopy
import itertools as it
import glob
from glob import iglob

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

# https://stackoverflow.com/a/4829130
def search_files(prefix, outtypes):
return it.chain.from_iterable(iglob(prefix + outtype) for outtype in outtypes)
return it.chain.from_iterable(
iglob(glob.escape(prefix + outtype)) for outtype in outtypes
)
21 changes: 21 additions & 0 deletions nipype/interfaces/tests/test_dcm2nii.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import pytest


from nipype.interfaces import dcm2nii


@pytest.mark.parametrize(
"fname, extension",
[
("output_1", ".txt"),
("output_w_[]_meta_1", ".json"),
("output_w_**^$?_meta_2", ".txt"),
],
)
def test_search_files(tmp_path, fname, extension):
tmp_fname = fname + extension
test_file = tmp_path / tmp_fname
test_file.touch()
actual_files_list = dcm2nii.search_files(str(tmp_path / fname), [extension])
for f in actual_files_list:
assert str(test_file) == f