Skip to content

Commit 044e95b

Browse files
Handle empty string config values: Change regex to avoid catastrophic backtracking and assign them to the dict as well.
1 parent c313e43 commit 044e95b

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

nf_core/utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,12 +326,15 @@ def fetch_wf_config(wf_path: Path, cache_config: bool = True) -> dict:
326326
if result is not None:
327327
nfconfig_raw, _ = result
328328
nfconfig = nfconfig_raw.decode("utf-8")
329-
multiline_key_value_pattern = re.compile(r"(^|\n)([^\n=]+?)\s*=\s*(.*?)(?=(\n[^\n=]+?\s*=)|$)", re.DOTALL)
329+
multiline_key_value_pattern = re.compile(r"(^|\n)([^\n=]+?)\s*=\s*((?:(?!\n[^\n=]+?\s*=).)*)", re.DOTALL)
330330

331331
for config_match in multiline_key_value_pattern.finditer(nfconfig):
332332
k = config_match.group(2).strip()
333333
v = config_match.group(3).strip().strip("'\"")
334-
if k and v:
334+
if k and v == "":
335+
config[k] = "" # or do we want to set it to "null"?
336+
log.debug(f"Config key: {k}, value: empty string")
337+
elif k and v:
335338
config[k] = v
336339
log.debug(f"Config key: {k}, value: {v}")
337340
else:

tests/pipelines/test_download.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def test__find_container_images_config_nextflow(self, tmp_path, mock_fetch_wf_co
222222
nfconfig_raw, _ = result
223223
config = {}
224224
nfconfig = nfconfig_raw.decode("utf-8")
225-
multiline_key_value_pattern = re.compile(r"(^|\n)([^\n=]+?)\s*=\s*(.*?)(?=(\n[^\n=]+?\s*=)|$)", re.DOTALL)
225+
multiline_key_value_pattern = re.compile(r"(^|\n)([^\n=]+?)\s*=\s*((?:(?!\n[^\n=]+?\s*=).)*)", re.DOTALL)
226226

227227
for match in multiline_key_value_pattern.finditer(nfconfig):
228228
k = match.group(2).strip()

0 commit comments

Comments
 (0)