Avoid fallthrough with empty defaults

Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
Joffrey F 2018-03-27 11:10:30 -07:00
parent 7e787a8c15
commit 71d40c2a9b
2 changed files with 14 additions and 3 deletions

View File

@ -133,9 +133,8 @@ class TemplateWithDefaults(Template):
braced = mo.group('braced')
if braced is not None:
sep = mo.group('sep')
result = self.process_braced_group(braced, sep, mapping)
if result:
return result
if sep:
return self.process_braced_group(braced, sep, mapping)
if named is not None:
val = mapping[named]

View File

@ -420,3 +420,15 @@ def test_interpolate_unicode_values():
interpol("$FOO") == '十六夜 咲夜'
interpol("${BAR}") == '十六夜 咲夜'
def test_interpolate_no_fallthrough():
# Test regression on docker/compose#5829
variable_mapping = {
'TEST:-': 'hello',
'TEST-': 'hello',
}
interpol = Interpolator(TemplateWithDefaults, variable_mapping).interpolate
assert interpol('${TEST:-}') == ''
assert interpol('${TEST-}') == ''