Skip to content

Commit b9bd808

Browse files
authored
Update regex for FnSub (#3878)
1 parent 310beb4 commit b9bd808

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/cfnlint/helpers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
REGEX_DYN_REF_SSM_SECURE = re.compile(
137137
r"^.*{{resolve:ssm-secure:[a-zA-Z0-9_\.\-/]+(:\d+)?}}.*$"
138138
)
139-
REGEX_SUB_PARAMETERS = re.compile(r"\${([^!].*?)}")
139+
REGEX_SUB_PARAMETERS = re.compile(r"\${\s*([^!\s].*?)\s*}")
140140

141141
FUNCTIONS = frozenset(
142142
[

test/unit/rules/functions/test_sub.py

+12
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,18 @@ def context(cfn):
162162
{"type": "string"},
163163
[],
164164
),
165+
(
166+
"Valid Fn::Sub with a space and escape char",
167+
{"Fn::Sub": "${ !Foo }"},
168+
{"type": "string"},
169+
[],
170+
),
171+
(
172+
"Valid Fn::Sub with a space and no escape char",
173+
{"Fn::Sub": "${ AWS::AccountId }"},
174+
{"type": "string"},
175+
[],
176+
),
165177
(
166178
"Invalid Fn::Sub with a too to many elements",
167179
{"Fn::Sub": ["${foo}", {"foo": "bar"}, {}]},

0 commit comments

Comments
 (0)