Skip to content

Commit c95d065

Browse files
authored
Merge pull request #1 from dklawson/master
Make Fn::Sub regex match non-greedy
2 parents 2858d0a + 0ef8923 commit c95d065

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

aws_parsecf/functions.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,15 @@ def fn_sub(self, value):
218218
"""
219219
>>> from aws_parsecf.parser import Parser
220220
221+
>>> root = {'Parameters': {'Who': {'Type': 'String', 'Default': 'world'},
222+
... 'When': {'Type': 'String', 'Default': 'NOW'}},
223+
... 'Fn::Sub': 'hello-${Who} ${When}'}
224+
>>> Functions(Parser(root, 'us-east-1'),
225+
... root,
226+
... 'us-east-1'
227+
... ).fn_sub('hello-${Who} ${When}')
228+
'hello-world NOW'
229+
221230
>>> root = {'Fn::Sub': ['hello-${Who} ${When}', {'Who': 'world', 'When': 'NOW'}]}
222231
>>> Functions(Parser(root, 'us-east-1'),
223232
... root,
@@ -385,7 +394,7 @@ def _find_att(self, current, key):
385394
return result
386395
raise KeyError(key)
387396

388-
SUB_VARIABLE_PATTERN = re.compile(r"\${(.+)}")
397+
SUB_VARIABLE_PATTERN = re.compile(r"\${(.+?)}")
389398
def _sub_variable(self, match):
390399
variable = match.group(1)
391400
if variable.startswith('!'):

0 commit comments

Comments
 (0)