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
Fix parsing of variable without a value
In Python, `\s` also matches newlines.  This would cause newlines to be
consumed by the equal sign matcher, resulting in the next line being
considered as a value.

For instance, the following would be parsed as `[("FOO", "BAR=b")]`
instead of [("FOO", ""), ("BAR", "b")].

```bash
FOO=
BAR=b
```

Fixes #157.
  • Loading branch information
bbc2 committed Dec 14, 2018
commit 921cc99d0a62fcb12475d890e1c9fbd1fa6f86bc
6 changes: 3 additions & 3 deletions dotenv/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
r"""
(
\s* # leading whitespace
(?:export\s+)? # export
(?:export{0}+)? # export

( '[^']+' # single-quoted key
| [^=\#\s]+ # or unquoted key
)?

(?:
(?:\s*=\s*) # equal sign
(?:{0}*={0}*) # equal sign

( '(?:\\'|[^'])*' # single-quoted value
| "(?:\\"|[^"])*" # or double-quoted value
Expand All @@ -40,7 +40,7 @@
(?:\#[^\r\n]*)? # comment
(?:\r|\n|\r\n)? # newline
)
""",
""".format(r'[^\S\r\n]'),
re.MULTILINE | re.VERBOSE,
)

Expand Down
7 changes: 7 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ def restore_os_environ():
Binding(key="c", value="d", original="c=d"),
],
),
(
'a=\nb=c',
[
Binding(key="a", value='', original='a=\n'),
Binding(key="b", value='c', original="b=c"),
]
),
(
'a="\nb=c',
[
Expand Down