Skip to content

Commit 4b1686f

Browse files
PiDelporttheskumar
authored andcommitted
Bugfix: parse_line incorrectly strips "export " prefix (theskumar#125)
* parse_line: Add failing tests for "export" stripping * parse_line: Strip using partition rather than lstrip This avoids accidentally stripping additional leading characters from the variable name.
1 parent d143c89 commit 4b1686f

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

dotenv/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def parse_line(line):
3131
k, v = line.split('=', 1)
3232

3333
if k.startswith('export '):
34-
k = k.lstrip('export ')
34+
(_, _, k) = k.partition('export ')
3535

3636
# Remove any leading and trailing spaces in key, value
3737
k, v = k.strip(), v.strip()

tests/test_core.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
("a=b space ", ('a', 'b space')),
2525
("a='b space '", ('a', 'b space ')),
2626
('a="b space "', ('a', 'b space ')),
27+
("export export_spam=1", ("export_spam", "1")),
28+
("export port=8000", ("port", "8000")),
2729
])
2830
def test_parse_line(test_input, expected):
2931
assert parse_line(test_input) == expected

0 commit comments

Comments
 (0)