Kaydet (Commit) 4e08a5cb authored tarafından Joffrey F's avatar Joffrey F Kaydeden (comit) GitHub

Merge pull request #1317 from bfirsh/fix-environment-variable-file-with-new-lines

Fix parsing for an environment file with newlines
...@@ -1052,7 +1052,11 @@ def parse_env_file(env_file): ...@@ -1052,7 +1052,11 @@ def parse_env_file(env_file):
if line[0] == '#': if line[0] == '#':
continue continue
parse_line = line.strip().split('=', 1) line = line.strip()
if not line:
continue
parse_line = line.split('=', 1)
if len(parse_line) == 2: if len(parse_line) == 2:
k, v = parse_line k, v = parse_line
environment[k] = v environment[k] = v
......
...@@ -465,10 +465,18 @@ class ParseEnvFileTest(unittest.TestCase): ...@@ -465,10 +465,18 @@ class ParseEnvFileTest(unittest.TestCase):
def test_parse_env_file_commented_line(self): def test_parse_env_file_commented_line(self):
env_file = self.generate_tempfile( env_file = self.generate_tempfile(
file_content='USER=jdoe\n#PASS=secret') file_content='USER=jdoe\n#PASS=secret')
get_parse_env_file = parse_env_file((env_file)) get_parse_env_file = parse_env_file(env_file)
self.assertEqual(get_parse_env_file, {'USER': 'jdoe'}) self.assertEqual(get_parse_env_file, {'USER': 'jdoe'})
os.unlink(env_file) os.unlink(env_file)
def test_parse_env_file_newline(self):
env_file = self.generate_tempfile(
file_content='\nUSER=jdoe\n\n\nPASS=secret')
get_parse_env_file = parse_env_file(env_file)
self.assertEqual(get_parse_env_file,
{'USER': 'jdoe', 'PASS': 'secret'})
os.unlink(env_file)
def test_parse_env_file_invalid_line(self): def test_parse_env_file_invalid_line(self):
env_file = self.generate_tempfile( env_file = self.generate_tempfile(
file_content='USER jdoe') file_content='USER jdoe')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment