Skip to content

Commit fa66e0b

Browse files
committed
Added support for special characters
1 parent e5d68ff commit fa66e0b

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

‎dotenv/main.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def parse_dotenv(dotenv_path):
100100
k, v = line.split('=', 1)
101101

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

105105
if len(v) > 0:
106106
quoted = v[0] == v[len(v) - 1] in ['"', "'"]
@@ -114,7 +114,7 @@ def parse_dotenv(dotenv_path):
114114
def resolve_nested_variables(values):
115115
def _replacement(name):
116116
"""
117-
get appropiate value for a variable name.
117+
get appropriate value for a variable name.
118118
first search in environ, if not found,
119119
then look into the dotenv variables
120120
"""

‎tests/test_cli.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ def test_value_with_quotes():
5858
sh.rm(dotenv_path)
5959

6060

61+
def test_value_with_special_characters():
62+
with open(dotenv_path, 'w') as f:
63+
f.write(r'TEST="}=&~{,(\5%{&;"')
64+
assert dotenv.get_key(dotenv_path, 'TEST') == r'}=&~{,(\5%{&;'
65+
sh.rm(dotenv_path)
66+
67+
with open(dotenv_path, 'w') as f:
68+
f.write(r"TEST='}=&~{,(\5%{&;'")
69+
assert dotenv.get_key(dotenv_path, 'TEST') == r'}=&~{,(\5%{&;'
70+
sh.rm(dotenv_path)
71+
72+
6173
def test_unset():
6274
sh.touch(dotenv_path)
6375
success, key_to_set, value_to_set = dotenv.set_key(dotenv_path, 'HELLO', 'WORLD')

0 commit comments

Comments
 (0)