Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for special characters #60

Merged
merged 1 commit into from
Aug 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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