From 71d40c2a9b346bb5e19d443f6ab5553a80a7b692 Mon Sep 17 00:00:00 2001 From: Joffrey F Date: Tue, 27 Mar 2018 11:10:30 -0700 Subject: [PATCH] Avoid fallthrough with empty defaults Signed-off-by: Joffrey F --- compose/config/interpolation.py | 5 ++--- tests/unit/config/interpolation_test.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/compose/config/interpolation.py b/compose/config/interpolation.py index 59a567bb2..8845d73b5 100644 --- a/compose/config/interpolation.py +++ b/compose/config/interpolation.py @@ -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] diff --git a/tests/unit/config/interpolation_test.py b/tests/unit/config/interpolation_test.py index 2ba698fbf..0d0e7d28d 100644 --- a/tests/unit/config/interpolation_test.py +++ b/tests/unit/config/interpolation_test.py @@ -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-}') == ''