Skip to content

Commit

Permalink
Added support for special characters (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
pjona authored and theskumar committed Aug 9, 2017
1 parent 285cf93 commit b7c6d1b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
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

0 comments on commit b7c6d1b

Please sign in to comment.