mirror of https://github.com/docker/compose.git
Add support for BOM-signed env files
Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
parent
947e98be38
commit
558df8fe2f
|
@ -32,7 +32,7 @@ def env_vars_from_file(filename):
|
|||
elif not os.path.isfile(filename):
|
||||
raise ConfigurationError("%s is not a file." % (filename))
|
||||
env = {}
|
||||
with contextlib.closing(codecs.open(filename, 'r', 'utf-8')) as fileobj:
|
||||
with contextlib.closing(codecs.open(filename, 'r', 'utf-8-sig')) as fileobj:
|
||||
for line in fileobj:
|
||||
line = line.strip()
|
||||
if line and not line.startswith('#'):
|
||||
|
|
|
@ -3,6 +3,11 @@ from __future__ import absolute_import
|
|||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import codecs
|
||||
|
||||
import pytest
|
||||
|
||||
from compose.config.environment import env_vars_from_file
|
||||
from compose.config.environment import Environment
|
||||
from tests import unittest
|
||||
|
||||
|
@ -38,3 +43,12 @@ class EnvironmentTest(unittest.TestCase):
|
|||
assert env.get_boolean('BAZ') is False
|
||||
assert env.get_boolean('FOOBAR') is True
|
||||
assert env.get_boolean('UNDEFINED') is False
|
||||
|
||||
def test_env_vars_from_file_bom(self):
|
||||
tmpdir = pytest.ensuretemp('env_file')
|
||||
self.addCleanup(tmpdir.remove)
|
||||
with codecs.open('{}/bom.env'.format(str(tmpdir)), 'w', encoding='utf-8') as f:
|
||||
f.write('\ufeffPARK_BOM=박봄\n')
|
||||
assert env_vars_from_file(str(tmpdir.join('bom.env'))) == {
|
||||
'PARK_BOM': '박봄'
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue