From 2116647e6471100ba9880a40f334b13990d19c73 Mon Sep 17 00:00:00 2001 From: aviat cohen Date: Mon, 12 Jan 2026 14:11:45 +0000 Subject: [PATCH] fix:update the argument-parameter regex to allow optional whitespace after commas --- .../unreleased/fixed-20260112-141104.yaml | 6 ++++ src/fabric_cli/utils/fab_util.py | 7 +--- tests/test_utils/test_fab_util.py | 34 +++++++++++++++++++ 3 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 .changes/unreleased/fixed-20260112-141104.yaml diff --git a/.changes/unreleased/fixed-20260112-141104.yaml b/.changes/unreleased/fixed-20260112-141104.yaml new file mode 100644 index 00000000..91002fd0 --- /dev/null +++ b/.changes/unreleased/fixed-20260112-141104.yaml @@ -0,0 +1,6 @@ +kind: fixed +body: Update the argument-parameter regex to allow optional whitespace after commas +time: 2026-01-12T14:11:04.576274188Z +custom: + Author: aviatco + AuthorLink: https://github.com/aviatco diff --git a/src/fabric_cli/utils/fab_util.py b/src/fabric_cli/utils/fab_util.py index c9873027..8312a386 100644 --- a/src/fabric_cli/utils/fab_util.py +++ b/src/fabric_cli/utils/fab_util.py @@ -62,7 +62,6 @@ def remove_dot_suffix(path: str, dot_string_to_rm: str = ".Shortcut") -> str: return path.replace(dot_string_to_rm, "").replace(dot_string_to_rm.lower(), "") - def get_dict_from_params(params: str | list[str], max_depth: int = 2) -> dict: """ Convert args to dict with a specified max nested level. @@ -76,7 +75,7 @@ def get_dict_from_params(params: str | list[str], max_depth: int = 2) -> dict: # Result ['key1.key2=hello', 'key2={"hello":"testing","bye":2}', 'key3=[1,2,3]', 'key4={"key5":"value5"}'] # Example key1.key2=hello # Result ['key1.key=hello'] - pattern = r"((?:[\w\.]+=.+?)(?=(?:,[\w\.]+=)|$))" + pattern = r"((?:[\w\.]+=.+?)(?=(?:,\s*[\w\.]+=)|$))" if params: if isinstance(params, list): @@ -166,8 +165,6 @@ def remove_keys_from_dict(_dict: dict, keys: list) -> dict: return _dict - - def get_os_specific_command(command: str) -> str: if platform.system() == "Windows": return fab_constant.OS_COMMANDS.get(command, {}).get("windows", command) @@ -237,5 +234,3 @@ def get_capacity_settings( az_resource_group, sku, ) - - diff --git a/tests/test_utils/test_fab_util.py b/tests/test_utils/test_fab_util.py index d836c980..fbf4a734 100644 --- a/tests/test_utils/test_fab_util.py +++ b/tests/test_utils/test_fab_util.py @@ -138,6 +138,40 @@ def test_get_dict_from_params(): "desc3": "hi", } + # Test space after comma - this tests the regex pattern fix that allows spaces after commas + params = "key1=value1, key2=value2, key3=value3" + result = utils.get_dict_from_params(params) + assert result == {"key1": "value1", "key2": "value2", "key3": "value3"} + + # Test multiple spaces after comma + params = "key1=value1, key2=value2, key3=value3" + result = utils.get_dict_from_params(params) + assert result == {"key1": "value1", "key2": "value2", "key3": "value3"} + + # Test mixed spacing (some with spaces, some without) + params = "key1=value1,key2=value2, key3=value3, key4=value4" + result = utils.get_dict_from_params(params) + assert result == {"key1": "value1", "key2": "value2", "key3": "value3", "key4": "value4"} + + # Test with nested keys and spaces + params = "key1.sub1=value1, key1.sub2=value2, key2=value3" + result = utils.get_dict_from_params(params) + assert result == {"key1": {"sub1": "value1", "sub2": "value2"}, "key2": "value3"} + + # Test with complex values and spaces + params = 'key1={"nested": "value"}, key2=[1,2,3], key3=simple' + result = utils.get_dict_from_params(params) + assert result == { + "key1": '{nested: value}', + "key2": "[1,2,3]", + "key3": "simple" + } + + # Test tabs and mixed whitespace after comma + params = "key1=value1,\tkey2=value2,\n key3=value3" + result = utils.get_dict_from_params(params) + assert result == {"key1": "value1", "key2": "value2", "key3": "value3"} + def test_merge_dicts(): dict1 = {"key1": "value1", "key2": {"key1": "value2"}}