From 176c3c6998da330b20930e127f522d173a24aabb Mon Sep 17 00:00:00 2001 From: AAYUSH ANAND Date: Mon, 28 Oct 2024 17:07:49 +0530 Subject: [PATCH 1/4] simplify value conversion by removing ast.literal_eval --- plugins/module_utils/network/common/utils.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/plugins/module_utils/network/common/utils.py b/plugins/module_utils/network/common/utils.py index 5576e7edf..770d0e1c3 100644 --- a/plugins/module_utils/network/common/utils.py +++ b/plugins/module_utils/network/common/utils.py @@ -685,11 +685,8 @@ def __call__(self, value, variables=None, fail_on_undefined=True): return None raise - if value: - try: - return ast.literal_eval(value) - except Exception: - return str(value) + if value is not None: + return str(value) # Ensuring we returning it as a string else: return None From 3081ccf3d827ae2d12495e08e2ff04dd66b24e13 Mon Sep 17 00:00:00 2001 From: AAYUSH ANAND Date: Mon, 28 Oct 2024 17:11:47 +0530 Subject: [PATCH 2/4] adding changelogs --- changelogs/fragments/utils.yaml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelogs/fragments/utils.yaml diff --git a/changelogs/fragments/utils.yaml b/changelogs/fragments/utils.yaml new file mode 100644 index 000000000..3c59ffe3a --- /dev/null +++ b/changelogs/fragments/utils.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: + - Simplifies value handling by returning direct string conversion instead of using ast.literal_eval From 39d306d48b16452de8a7ab768620a9557ab462e5 Mon Sep 17 00:00:00 2001 From: AAYUSH ANAND Date: Mon, 28 Oct 2024 18:17:31 +0530 Subject: [PATCH 3/4] changing logic to handle value --- plugins/module_utils/network/common/utils.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/plugins/module_utils/network/common/utils.py b/plugins/module_utils/network/common/utils.py index 770d0e1c3..e8404e0ec 100644 --- a/plugins/module_utils/network/common/utils.py +++ b/plugins/module_utils/network/common/utils.py @@ -684,12 +684,15 @@ def __call__(self, value, variables=None, fail_on_undefined=True): if not fail_on_undefined: return None raise - + if value is not None: - return str(value) # Ensuring we returning it as a string + # Special handling for values starting with + + if isinstance(value, str) and value.startswith('+'): + return value # Keep the + prefix intact + return str(value) # Convert everything else to string else: return None - + def contains_vars(self, data): if isinstance(data, string_types): for marker in ( From d30268653fbb172807edc5ab2643ca44dd963549 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 28 Oct 2024 12:47:56 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- plugins/module_utils/network/common/utils.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/module_utils/network/common/utils.py b/plugins/module_utils/network/common/utils.py index e8404e0ec..fccb5b348 100644 --- a/plugins/module_utils/network/common/utils.py +++ b/plugins/module_utils/network/common/utils.py @@ -684,15 +684,15 @@ def __call__(self, value, variables=None, fail_on_undefined=True): if not fail_on_undefined: return None raise - + if value is not None: - # Special handling for values starting with + - if isinstance(value, str) and value.startswith('+'): + # Special handling for values starting with + + if isinstance(value, str) and value.startswith("+"): return value # Keep the + prefix intact return str(value) # Convert everything else to string else: return None - + def contains_vars(self, data): if isinstance(data, string_types): for marker in (