From 223132c510a0c53b30ff6cc16ae5bebe2ebcc199 Mon Sep 17 00:00:00 2001 From: Kevin DeJong Date: Fri, 25 Oct 2024 07:14:39 -0700 Subject: [PATCH] Trim comma delimited lists for context (#3790) --- src/cfnlint/context/context.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/cfnlint/context/context.py b/src/cfnlint/context/context.py index e75efeb1b5..c5c4e5083a 100644 --- a/src/cfnlint/context/context.py +++ b/src/cfnlint/context/context.py @@ -278,6 +278,12 @@ def ref(self, context: Context) -> Iterator[Any]: pass +def _strip(value: Any) -> Any: + if isinstance(value, str): + return value.strip() + return value + + @dataclass class Parameter(_Ref): """ @@ -321,14 +327,17 @@ def __post_init__(self, parameter) -> None: if "Default" in parameter: default = parameter.get("Default", "") if isinstance(default, str): - self.default = default.split(",") + self.default = [_strip(value) for value in default.split(",")] else: - self.default = [default] + self.default = [_strip(default)] + for allowed_value in parameter.get("AllowedValues", []): if isinstance(allowed_value, str): - self.allowed_values.append(allowed_value.split(",")) + self.allowed_values.append( + [_strip(value) for value in allowed_value.split(",")] + ) else: - self.allowed_values.append([allowed_value]) + self.allowed_values.append([_strip(allowed_value)]) else: self.default = parameter.get("Default") self.allowed_values = parameter.get("AllowedValues")