Skip to content

Commit

Permalink
Trim comma delimited lists for context (#3790)
Browse files Browse the repository at this point in the history
  • Loading branch information
kddejong authored Oct 25, 2024
1 parent eea0801 commit 223132c
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 223132c

Please sign in to comment.