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

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Added support for special characters
  • Loading branch information
pjona committed Aug 8, 2017
commit fa66e0bbec3e7119eebb634114c1d39bb8d61bca
4 changes: 2 additions & 2 deletions dotenv/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def parse_dotenv(dotenv_path):
k, v = line.split('=', 1)

# Remove any leading and trailing spaces in key, value
k, v = k.strip(), v.strip()
k, v = k.strip(), v.strip().encode('unicode-escape').decode('ascii')

if len(v) > 0:
quoted = v[0] == v[len(v) - 1] in ['"', "'"]
Expand All @@ -114,7 +114,7 @@ def parse_dotenv(dotenv_path):
def resolve_nested_variables(values):
def _replacement(name):
"""
get appropiate value for a variable name.
get appropriate value for a variable name.
first search in environ, if not found,
then look into the dotenv variables
"""
Expand Down
12 changes: 12 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ def test_value_with_quotes():
sh.rm(dotenv_path)


def test_value_with_special_characters():
with open(dotenv_path, 'w') as f:
f.write(r'TEST="}=&~{,(\5%{&;"')
assert dotenv.get_key(dotenv_path, 'TEST') == r'}=&~{,(\5%{&;'
sh.rm(dotenv_path)

with open(dotenv_path, 'w') as f:
f.write(r"TEST='}=&~{,(\5%{&;'")
assert dotenv.get_key(dotenv_path, 'TEST') == r'}=&~{,(\5%{&;'
sh.rm(dotenv_path)


def test_unset():
sh.touch(dotenv_path)
success, key_to_set, value_to_set = dotenv.set_key(dotenv_path, 'HELLO', 'WORLD')
Expand Down