From a91eae352485b89db96258deb8d8ac45375beb92 Mon Sep 17 00:00:00 2001 From: Pavel Cahyna Date: Mon, 27 Oct 2025 14:32:30 +0100 Subject: [PATCH 1/2] Fix parsing of --config argument with whitespace Uses argv properly instead of concatenating all arguments in a single string and searching for the --config argument inside it. Fixes also some other corner cases: - The "--config " string in the middle of another arguemnt is not interpereted as a --config argument anymore. - "--confg" argument is not accepted anymore (used to be an alias for --config). --- did/base.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/did/base.py b/did/base.py index 0ba5ad1a..696a1dba 100644 --- a/did/base.py +++ b/did/base.py @@ -259,11 +259,19 @@ def path() -> str: directory = CONFIG # Detect config file (even before options are parsed) filename = "config" - matched = re.search(r"--confi?g?[ =](\S+)", " ".join(sys.argv)) - if matched: - filepath, filename = os.path.split(matched.groups()[0]) - if filepath: - directory = filepath + for i, a in enumerate(sys.argv): + matched = re.match(r"--conf(?:ig?)?(?:=(.*))?$", a) + if matched: + if matched.groups()[0] is not None: + arg = matched.groups()[0] + elif i+1 < len(sys.argv): + arg = sys.argv[i+1] + else: + arg = "" + filepath, filename = os.path.split(arg) + if filepath: + directory = filepath + break return os.path.join(directory.rstrip("/"), filename) @staticmethod From 58c8db8a8b8c23fbd4a07cd3eb78aa3cdfafaee4 Mon Sep 17 00:00:00 2001 From: Pavel Cahyna Date: Tue, 11 Nov 2025 10:52:08 +0100 Subject: [PATCH 2/2] fixup! Fix parsing of --config argument with whitespace --- did/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/did/base.py b/did/base.py index 696a1dba..3971e78c 100644 --- a/did/base.py +++ b/did/base.py @@ -264,8 +264,8 @@ def path() -> str: if matched: if matched.groups()[0] is not None: arg = matched.groups()[0] - elif i+1 < len(sys.argv): - arg = sys.argv[i+1] + elif i + 1 < len(sys.argv): + arg = sys.argv[i + 1] else: arg = "" filepath, filename = os.path.split(arg)