Skip to content

Commit 9b5582e

Browse files
committed
Parse single quotes
1 parent a2096aa commit 9b5582e

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

‎dotenv/main.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def parse_dotenv(dotenv_path):
103103
k, v = k.strip(), v.strip()
104104

105105
if len(v) > 0:
106-
quoted = v[0] == v[len(v) - 1] == '"'
106+
quoted = v[0] == v[len(v) - 1] in ['"', "'"]
107107

108108
if quoted:
109109
v = decode_escaped(v[1:-1])

‎tests/test_cli.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ def test_key_value_without_quotes():
4646
sh.rm(dotenv_path)
4747

4848

49+
def test_value_with_quotes():
50+
with open(dotenv_path, 'w') as f:
51+
f.write('TEST="two words"\n')
52+
assert dotenv.get_key(dotenv_path, 'TEST') == 'two words'
53+
sh.rm(dotenv_path)
54+
55+
with open(dotenv_path, 'w') as f:
56+
f.write("TEST='two words'\n")
57+
assert dotenv.get_key(dotenv_path, 'TEST') == 'two words'
58+
sh.rm(dotenv_path)
59+
60+
4961
def test_unset():
5062
sh.touch(dotenv_path)
5163
success, key_to_set, value_to_set = dotenv.set_key(dotenv_path, 'HELLO', 'WORLD')

0 commit comments

Comments
 (0)