Skip to content

Commit 0441367

Browse files
committed
Fixed IndexError when parsing malformed --modules-extra-args
- Added validation to check for '=' sign before splitting - Provided the helpful error message when format is invalid - Used split('=', 1) to properly handle values containing '=' characters - Fixes issue #1199
1 parent 3ce1e88 commit 0441367

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

nettacker/core/arg_parser.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,20 @@ def parse_arguments(self):
736736
if options.modules_extra_args:
737737
all_args = {}
738738
for args in options.modules_extra_args.split("&"):
739-
value = args.split("=")[1]
739+
# Validate format
740+
if "=" not in args:
741+
die_failure(
742+
f"Invalid format for --modules-extra-args: '{args}'\n"
743+
f"Expected format: key1=value1&key2=value2\n"
744+
f"Example: --modules-extra-args \"x_api_key=123&xyz_passwd=abc\""
745+
)
746+
747+
# Split with maxsplit=1 to handle values containing '='
748+
parts = args.split("=", 1)
749+
key = parts[0]
750+
value = parts[1]
751+
752+
# Type conversion logic
740753
if value.lower() == "true":
741754
value = True
742755
elif value.lower() == "false":
@@ -756,7 +769,8 @@ def parse_arguments(self):
756769
value = int(value)
757770
except Exception:
758771
pass
759-
all_args[args.split("=")[0]] = value
772+
773+
all_args[key] = value
760774
options.modules_extra_args = all_args
761775

762776
options.timeout = float(options.timeout)

0 commit comments

Comments
 (0)