Skip to content

Commit

Permalink
Trim comma delimited lists for context
Browse files Browse the repository at this point in the history
  • Loading branch information
kddejong committed Oct 24, 2024
1 parent 74847b1 commit 8570b45
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/cfnlint/context/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 8570b45

Please sign in to comment.