Skip to content

Commit

Permalink
Update regex for FnSub
Browse files Browse the repository at this point in the history
  • Loading branch information
kddejong committed Dec 12, 2024
1 parent 310beb4 commit 6ebbbd6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/cfnlint/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
REGEX_DYN_REF_SSM_SECURE = re.compile(
r"^.*{{resolve:ssm-secure:[a-zA-Z0-9_\.\-/]+(:\d+)?}}.*$"
)
REGEX_SUB_PARAMETERS = re.compile(r"\${([^!].*?)}")
REGEX_SUB_PARAMETERS = re.compile(r"\${\s*([^!\s].*?)\s*}")

FUNCTIONS = frozenset(
[
Expand Down
12 changes: 12 additions & 0 deletions test/unit/rules/functions/test_sub.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,18 @@ def context(cfn):
{"type": "string"},
[],
),
(
"Valid Fn::Sub with a space and escape char",
{"Fn::Sub": "${ !Foo }"},
{"type": "string"},
[],
),
(
"Valid Fn::Sub with a space and no escape char",
{"Fn::Sub": "${ AWS::AccountId }"},
{"type": "string"},
[],
),
(
"Invalid Fn::Sub with a too to many elements",
{"Fn::Sub": ["${foo}", {"foo": "bar"}, {}]},
Expand Down

0 comments on commit 6ebbbd6

Please sign in to comment.