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

Allow multi-line ENV values #142

Closed
wants to merge 3 commits into from
Closed

Allow multi-line ENV values #142

wants to merge 3 commits into from

Conversation

amancevice
Copy link

@amancevice amancevice commented Oct 3, 2018

Use regex to parse ENV variable names from .env

Example .env file that is currently not parsed correctly (this is not a real private key):

PRIVATE_KEY='-----BEGIN RSA PRIVATE KEY-----
MIICXgIBAAKBgQCiiy07/kQ/O9bQgIbg/+RjjPEfqvalNqZPHjKW0rqL3E3fGvOe
dksb0IsHJKS80Va+jtz7pO2nuLjQ2pYm7StQO/8ya0WnmndL12kTSR+Kjbr4WHJV
ZH3pXA+E2rdubHnodD5uHMrlqPsgrmAtHTTHww0GB1hfAQb1HNx8GezauwIDAQAB
AoGABNdgYYkRP1Do9Qze95SnmM953xeYgRM/oNulZhigtcm6CAsldnLPieSMP4o3
3efeTY6zxksDSRuXZaEdF8u4nn60L2M3oAbL6JPplLgCjRNW2q9mIBQ0rChEFHrU
oBwTcEE/H8RfaAJu7baT4PQXU9jk1DxqGCPiTkNGetGqKAECQQD/yMwprtUSEKA4
SGA5HtCXfZSE6M5698okL2VcmZlzdYFh0wWGNZHgBoR/N3obv7ioqr74UboxM0Yi
psdGE1mhAkEAoq5BnP9QpDZ9eywoXLBSXqR3/WXsYIHgq0ETC5xlquma6qHVPo+B
tSkMxgg8c8fzy5tPSf/AWwwOxSD5AVxu2wJBANkLT0sTgtPobbw0lgoCPug9dJhv
YD5yIwIfgbhY0iBqFlanFKn0rQrXHPlCXwhK4GunL5NQ7livdJUUxkWNR+ECQQCH
zXn+inASNV641Rr4jUSltxxnj48s3R7lN1Sjy7JfY9Wr6t7t87Ruu87q/fMhIBkX
rhYZiwNTvhQSYb0ccsIjAkEA3qDEu1ouTHGAbLguryJ5uw10oEROYuydt55qeT05
IV/wDZ9X6+qJE+BBatO9T+fJGSzKOBCFhmdVdbOLs1t2g==
-----END RSA PRIVATE KEY-----'
PRIVATE_KEY_ID='fizzbuzz'

@coveralls
Copy link

coveralls commented Oct 3, 2018

Coverage Status

Coverage increased (+0.4%) to 93.015% when pulling 889da50 on amancevice:newline into 40ed1b1 on theskumar:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.4%) to 93.015% when pulling 4c1d4a9 on amancevice:newline into 40ed1b1 on theskumar:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage increased (+0.4%) to 93.015% when pulling 4c1d4a9 on amancevice:newline into 40ed1b1 on theskumar:master.

@amancevice
Copy link
Author

Turns out I needed to add some TLC to the requirements.txt for Python 3.3 compatibility:

IPython 7 is not compatible with Python 3.3
IPython 6 is compatible, but jedi 0.13 is not

Alexander Mancevice added 3 commits October 4, 2018 17:27
IPython 7+ only works with Python 3.5+
IPython 6+ only works with Python 3+
IPython 5 works with Python 2
Jedi v0.13 drops support for Python 3.3
Use regex to parse ENV variable names from .env
bbc2 added a commit to bbc2/python-dotenv that referenced this pull request Oct 28, 2018
This adds support for:

* multiline values (i.e. containing newlines or escaped \n), fixes theskumar#89
* backslashes in values, fixes theskumar#112
* trailing comments, fixes theskumar#141
* UTF-8 in unquoted values, fixes theskumar#147

Parsing is no longer line-based.  That's why `parse_line` was replaced
by `parse_binding`.  Thanks to the previous commit, users of
`parse_stream` don't have to deal with this change.

This supersedes a previous pull-request, theskumar#142, which would add support for
multiline values in `Dotenv.parse` but not in the CLI (`dotenv get` and `dotenv
set`).

The key-value binding regular expression was inspired by
https://github.com/bkeepers/dotenv/blob/d749366b6009126b115fb7b63e0509566365859a/lib/dotenv/parser.rb#L14-L30

Parsing of escapes was fixed thanks to
https://stackoverflow.com/questions/4020539/process-escape-sequences-in-a-string-in-python/24519338#24519338
bbc2 added a commit to bbc2/python-dotenv that referenced this pull request Oct 28, 2018
This adds support for:

* multiline values (i.e. containing newlines or escaped \n), fixes theskumar#89
* backslashes in values, fixes theskumar#112
* trailing comments, fixes theskumar#141
* UTF-8 in unquoted values, fixes theskumar#147

Parsing is no longer line-based.  That's why `parse_line` was replaced
by `parse_binding`.  Thanks to the previous commit, users of
`parse_stream` don't have to deal with this change.

This supersedes a previous pull-request, theskumar#142, which would add support for
multiline values in `Dotenv.parse` but not in the CLI (`dotenv get` and `dotenv
set`).

The key-value binding regular expression was inspired by
https://github.com/bkeepers/dotenv/blob/d749366b6009126b115fb7b63e0509566365859a/lib/dotenv/parser.rb#L14-L30

Parsing of escapes was fixed thanks to
https://stackoverflow.com/questions/4020539/process-escape-sequences-in-a-string-in-python/24519338#24519338
bbc2 added a commit to bbc2/python-dotenv that referenced this pull request Oct 28, 2018
This adds support for:

* multiline values (i.e. containing newlines or escaped \n), fixes theskumar#89
* backslashes in values, fixes theskumar#112
* trailing comments, fixes theskumar#141
* UTF-8 in unquoted values, fixes theskumar#147

Parsing is no longer line-based.  That's why `parse_line` was replaced
by `parse_binding`.  Thanks to the previous commit, users of
`parse_stream` don't have to deal with this change.

This supersedes a previous pull-request, theskumar#142, which would add support for
multiline values in `Dotenv.parse` but not in the CLI (`dotenv get` and `dotenv
set`).

The key-value binding regular expression was inspired by
https://github.com/bkeepers/dotenv/blob/d749366b6009126b115fb7b63e0509566365859a/lib/dotenv/parser.rb#L14-L30

Parsing of escapes was fixed thanks to
https://stackoverflow.com/questions/4020539/process-escape-sequences-in-a-string-in-python/24519338#24519338
bbc2 added a commit to bbc2/python-dotenv that referenced this pull request Oct 28, 2018
This adds support for:

* multiline values (i.e. containing newlines or escaped \n), fixes theskumar#89
* backslashes in values, fixes theskumar#112
* trailing comments, fixes theskumar#141
* UTF-8 in unquoted values, fixes theskumar#147

Parsing is no longer line-based.  That's why `parse_line` was replaced
by `parse_binding`.  Thanks to the previous commit, users of
`parse_stream` don't have to deal with this change.

This supersedes a previous pull-request, theskumar#142, which would add support for
multiline values in `Dotenv.parse` but not in the CLI (`dotenv get` and `dotenv
set`).

The key-value binding regular expression was inspired by
https://github.com/bkeepers/dotenv/blob/d749366b6009126b115fb7b63e0509566365859a/lib/dotenv/parser.rb#L14-L30

Parsing of escapes was fixed thanks to
https://stackoverflow.com/questions/4020539/process-escape-sequences-in-a-string-in-python/24519338#24519338
bbc2 added a commit to bbc2/python-dotenv that referenced this pull request Oct 28, 2018
This adds support for:

* multiline values (i.e. containing newlines or escaped \n), fixes theskumar#89
* backslashes in values, fixes theskumar#112
* trailing comments, fixes theskumar#141
* UTF-8 in unquoted values, fixes theskumar#147

Parsing is no longer line-based.  That's why `parse_line` was replaced
by `parse_binding`.  Thanks to the previous commit, users of
`parse_stream` don't have to deal with this change.

This supersedes a previous pull-request, theskumar#142, which would add support for
multiline values in `Dotenv.parse` but not in the CLI (`dotenv get` and `dotenv
set`).

The key-value binding regular expression was inspired by
https://github.com/bkeepers/dotenv/blob/d749366b6009126b115fb7b63e0509566365859a/lib/dotenv/parser.rb#L14-L30

Parsing of escapes was fixed thanks to
https://stackoverflow.com/questions/4020539/process-escape-sequences-in-a-string-in-python/24519338#24519338
bbc2 added a commit to bbc2/python-dotenv that referenced this pull request Oct 28, 2018
This adds support for:

* multiline values (i.e. containing newlines or escaped \n), fixes theskumar#89
* backslashes in values, fixes theskumar#112
* trailing comments, fixes theskumar#141
* UTF-8 in unquoted values, fixes theskumar#147

Parsing is no longer line-based.  That's why `parse_line` was replaced
by `parse_binding`.  Thanks to the previous commit, users of
`parse_stream` don't have to deal with this change.

This supersedes a previous pull-request, theskumar#142, which would add support for
multiline values in `Dotenv.parse` but not in the CLI (`dotenv get` and `dotenv
set`).

The key-value binding regular expression was inspired by
https://github.com/bkeepers/dotenv/blob/d749366b6009126b115fb7b63e0509566365859a/lib/dotenv/parser.rb#L14-L30

Parsing of escapes was fixed thanks to
https://stackoverflow.com/questions/4020539/process-escape-sequences-in-a-string-in-python/24519338#24519338
bbc2 added a commit to bbc2/python-dotenv that referenced this pull request Oct 28, 2018
This adds support for:

* multiline values (i.e. containing newlines or escaped \n), fixes theskumar#89
* backslashes in values, fixes theskumar#112
* trailing comments, fixes theskumar#141
* UTF-8 in unquoted values, fixes theskumar#147

Parsing is no longer line-based.  That's why `parse_line` was replaced
by `parse_binding`.  Thanks to the previous commit, users of
`parse_stream` don't have to deal with this change.

This supersedes a previous pull-request, theskumar#142, which would add support for
multiline values in `Dotenv.parse` but not in the CLI (`dotenv get` and `dotenv
set`).

The key-value binding regular expression was inspired by
https://github.com/bkeepers/dotenv/blob/d749366b6009126b115fb7b63e0509566365859a/lib/dotenv/parser.rb#L14-L30

Parsing of escapes was fixed thanks to
https://stackoverflow.com/questions/4020539/process-escape-sequences-in-a-string-in-python/24519338#24519338
@theskumar
Copy link
Owner

#148 will supercede this one. I'll have to close this.

@theskumar theskumar closed this Oct 31, 2018
bbc2 added a commit to bbc2/python-dotenv that referenced this pull request Oct 31, 2018
This adds support for:

* multiline values (i.e. containing newlines or escaped \n), fixes theskumar#89
* backslashes in values, fixes theskumar#112
* trailing comments, fixes theskumar#141
* UTF-8 in unquoted values, fixes theskumar#147

Parsing is no longer line-based.  That's why `parse_line` was replaced
by `parse_binding`.  Thanks to the previous commit, users of
`parse_stream` don't have to deal with this change.

This supersedes a previous pull-request, theskumar#142, which would add support for
multiline values in `Dotenv.parse` but not in the CLI (`dotenv get` and `dotenv
set`).

The key-value binding regular expression was inspired by
https://github.com/bkeepers/dotenv/blob/d749366b6009126b115fb7b63e0509566365859a/lib/dotenv/parser.rb#L14-L30

Parsing of escapes was fixed thanks to
https://stackoverflow.com/questions/4020539/process-escape-sequences-in-a-string-in-python/24519338#24519338
bbc2 added a commit to bbc2/python-dotenv that referenced this pull request Nov 14, 2018
This adds support for:

* multiline values (i.e. containing newlines or escaped \n), fixes theskumar#89
* backslashes in values, fixes theskumar#112
* trailing comments, fixes theskumar#141
* UTF-8 in unquoted values, fixes theskumar#147

Parsing is no longer line-based.  That's why `parse_line` was replaced
by `parse_binding`.  Thanks to the previous commit, users of
`parse_stream` don't have to deal with this change.

This supersedes a previous pull-request, theskumar#142, which would add support for
multiline values in `Dotenv.parse` but not in the CLI (`dotenv get` and `dotenv
set`).

The key-value binding regular expression was inspired by
https://github.com/bkeepers/dotenv/blob/d749366b6009126b115fb7b63e0509566365859a/lib/dotenv/parser.rb#L14-L30

Parsing of escapes was fixed thanks to
https://stackoverflow.com/questions/4020539/process-escape-sequences-in-a-string-in-python/24519338#24519338
theskumar pushed a commit that referenced this pull request Dec 5, 2018
… UTF-8 (#148)

* Fix deprecation warning for POSIX variable regex

This was also caught by Flake8 as:

    ./dotenv/main.py:19:2: W605 invalid escape sequence '\$'
    ./dotenv/main.py:19:4: W605 invalid escape sequence '\{'
    ./dotenv/main.py:19:8: W605 invalid escape sequence '\}'
    ./dotenv/main.py:19:12: W605 invalid escape sequence '\}'

* Turn get_stream into a context manager

This avoids the use of the `is_file` class variable by abstracting away
the difference between `StringIO` and a file stream.

* Deduplicate parsing code and abstract away lines

Parsing .env files is a critical part of this package.  To make it
easier to change it and test it, it is important that it is done in only
one place.

Also, code that uses the parser now doesn't depend on the fact that each
key-value binding spans exactly one line.  This will make it easier to
handle multiline bindings in the future.

* Parse newline, UTF-8, trailing comment, backslash

This adds support for:

* multiline values (i.e. containing newlines or escaped \n), fixes #89
* backslashes in values, fixes #112
* trailing comments, fixes #141
* UTF-8 in unquoted values, fixes #147

Parsing is no longer line-based.  That's why `parse_line` was replaced
by `parse_binding`.  Thanks to the previous commit, users of
`parse_stream` don't have to deal with this change.

This supersedes a previous pull-request, #142, which would add support for
multiline values in `Dotenv.parse` but not in the CLI (`dotenv get` and `dotenv
set`).

The key-value binding regular expression was inspired by
https://github.com/bkeepers/dotenv/blob/d749366b6009126b115fb7b63e0509566365859a/lib/dotenv/parser.rb#L14-L30

Parsing of escapes was fixed thanks to
https://stackoverflow.com/questions/4020539/process-escape-sequences-in-a-string-in-python/24519338#24519338
johnbergvall pushed a commit to johnbergvall/python-dotenv that referenced this pull request Aug 13, 2021
… UTF-8 (theskumar#148)

* Fix deprecation warning for POSIX variable regex

This was also caught by Flake8 as:

    ./dotenv/main.py:19:2: W605 invalid escape sequence '\$'
    ./dotenv/main.py:19:4: W605 invalid escape sequence '\{'
    ./dotenv/main.py:19:8: W605 invalid escape sequence '\}'
    ./dotenv/main.py:19:12: W605 invalid escape sequence '\}'

* Turn get_stream into a context manager

This avoids the use of the `is_file` class variable by abstracting away
the difference between `StringIO` and a file stream.

* Deduplicate parsing code and abstract away lines

Parsing .env files is a critical part of this package.  To make it
easier to change it and test it, it is important that it is done in only
one place.

Also, code that uses the parser now doesn't depend on the fact that each
key-value binding spans exactly one line.  This will make it easier to
handle multiline bindings in the future.

* Parse newline, UTF-8, trailing comment, backslash

This adds support for:

* multiline values (i.e. containing newlines or escaped \n), fixes theskumar#89
* backslashes in values, fixes theskumar#112
* trailing comments, fixes theskumar#141
* UTF-8 in unquoted values, fixes theskumar#147

Parsing is no longer line-based.  That's why `parse_line` was replaced
by `parse_binding`.  Thanks to the previous commit, users of
`parse_stream` don't have to deal with this change.

This supersedes a previous pull-request, theskumar#142, which would add support for
multiline values in `Dotenv.parse` but not in the CLI (`dotenv get` and `dotenv
set`).

The key-value binding regular expression was inspired by
https://github.com/bkeepers/dotenv/blob/d749366b6009126b115fb7b63e0509566365859a/lib/dotenv/parser.rb#L14-L30

Parsing of escapes was fixed thanks to
https://stackoverflow.com/questions/4020539/process-escape-sequences-in-a-string-in-python/24519338#24519338
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants