Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions compose/config/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ def split_env(env):
key = value = None
if '=' in env:
key, value = env.split('=', 1)
# If the value is quoted, remove the quotes
if len(value) >= 2 and value[0] == value[-1] and value[0] in ['"', "'"]:
value = value[1:-1]
# unescape quoted values
quote = value[0]
value.replace("\\"+quote, quote)
else:
key = env
if re.search(r'\s', key):
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/config/environment_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,14 @@ def test_env_vars_from_file_whitespace(self):
with pytest.raises(ConfigurationError) as exc:
env_vars_from_file(str(tmpdir.join('whitespace.env')))
assert 'environment variable' in exc.exconly()

def test_env_vars_from_file_quoted(self):
tmpdir = pytest.ensuretemp('env_file')
self.addCleanup(tmpdir.remove)
with codecs.open('{}/quoted.env'.format(str(tmpdir)), 'w', encoding='utf-8') as f:
f.write('DOUBLE_QUOTES="testing \"double\" quotes"\n')
f.write("SINGLE_QUOTES='testing \'single\' quotes'\n")
assert env_vars_from_file(str(tmpdir.join('quoted.env'))) == {
'DOUBLE_QUOTES': 'testing "double" quotes',
'SINGLE_QUOTES': "testing 'single' quotes",
}