Skip to content

Commit

Permalink
Fix .env -file quote strip.
Browse files Browse the repository at this point in the history
Remove only first and last quotes.
  • Loading branch information
Harry Karvonen committed Sep 29, 2021
1 parent 82a58b6 commit 79e1c0a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion decouple.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def __init__(self, source, encoding=DEFAULT_ENCODING):
k = k.strip()
v = v.strip()
if len(v) >= 2 and ((v[0] == "'" and v[-1] == "'") or (v[0] == '"' and v[-1] == '"')):
v = v.strip('\'"')
v = v[1:-1]
self.data[k] = v

def __contains__(self, key):
Expand Down
4 changes: 4 additions & 0 deletions tests/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
KeyWithDoubleQuoteBegin="text
KeyIsSingleQuote='
KeyIsDoubleQuote="
KeyHasTwoSingleQuote="'Y'"
KeyHasTwoDoubleQuote='"Y"'
'''

@pytest.fixture(scope='module')
Expand Down Expand Up @@ -128,3 +130,5 @@ def test_env_with_quote(config):
assert '"text' == config('KeyWithDoubleQuoteBegin')
assert '"' == config('KeyIsDoubleQuote')
assert "'" == config('KeyIsSingleQuote')
assert "'Y'" == config('KeyHasTwoSingleQuote')
assert '"Y"' == config('KeyHasTwoDoubleQuote')

0 comments on commit 79e1c0a

Please sign in to comment.