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

Refactor parser to fix inconsistencies #180

Merged
merged 4 commits into from
May 22, 2019

Conversation

bbc2
Copy link
Collaborator

@bbc2 bbc2 commented May 21, 2019

This fixes inconsistencies reported after the release of version 0.10.0 (comments in #148):

  • Valid escapes were interpreted as control characters even when in single-quoted strings.
  • # was interpreted as the start of a comment even if there was no whitespace preceding it.

However, we are keeping the interpretation of escapes in double-quoted strings as they didn't make sense in versions before 0.10.0.

The single large regular expression is replaced with a handwritten top-down parser using smaller regular expressions. The reason for this change is that it would have been very difficult or impossible to satisfy the parsing requirements with a single regex.

See individual commits to understand the changes better.

Fixes #170.

bbc2 added 4 commits May 14, 2019 00:33
Using `str` (e.g. `bytes`) is inconsistent with the types and the
implementation.
This fixes inconsistencies reported after the release of version 0.10.0:

* Valid escapes were interpreted as control characters even when in
  single-quoted strings.
* `#` was interpreted as the start of a comment even if there was no
  whitespace preceding it.

However, we are keeping the interpretation of escapes in double-quoted
strings as they didn't make sense in versions before 0.10.0.

The single large regular expression is replaced with a handwritten
top-down parser using smaller regular expressions.  The reason for this
change is that it would have been very difficult or impossible to
satisfy the parsing requirements with a single regex.
@bbc2 bbc2 requested a review from theskumar May 21, 2019 21:56
@coveralls
Copy link

Coverage Status

Coverage increased (+1.5%) to 90.217% when pulling e520f20 on bbc2:top-down-parser into 73124de on theskumar:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage increased (+1.5%) to 90.217% when pulling e520f20 on bbc2:top-down-parser into 73124de on theskumar:master.

@theskumar
Copy link
Owner

I really liked the top-down parser approach, it will be a lot easier to maintain and debug now. Reviewed the code and it all look great! Thank you so much!

@theskumar theskumar merged commit 57f9639 into theskumar:master May 22, 2019
@AEHamrick
Copy link

Would this be applicable to the behavior I'm seeing in pypa/pipenv#3757 with dotenv (by way of pipenv)? Will gladly open a new issue if not.

@bbc2
Copy link
Collaborator Author

bbc2 commented May 23, 2019

Yes, I believe we fixed the double-escaping issue in 0.10.0. See #170 for more information.

@bbc2 bbc2 deleted the top-down-parser branch May 23, 2019 18:02
theskumar pushed a commit that referenced this pull request Jun 2, 2019
* master: (49 commits)
  Fix typo in README.md (#181)
  Refactor move run_command in cli
  Refractor: move 'to_env' to compat.py
  Refactor parser to fix inconsistencies (#180)
  chore(pypi): switch to markdown and twine for pypi upload + update supported version
  Bump version: 0.10.1 → 0.10.2
  readme: Add new release stub
  Fix unicode/str inconsistency in Python 2 (#177)
  Add argument to choose .env file encoding, defaults to None
  Fix links in readme
  Restrict typing dependency to Python < 3.5
  Add type hints and expose them to users
  Updated `.gitignore` with results from https://www.gitignore.io/api/python
  Added special case for `__file__` in Python 2.  Fixes #130 Updated tests to show that this works.
  Moved `dotenv` package into `src` directory so that tests run against installed version. Added tox to run test suite against multiple versions of Python (with coverage) and run flake8. Updated Travis CI to use tox as well. Updated documentation about running tests.
  Fix ResourceWarning: unclosed file in setup.py and test_cli.py
  Clarify the usuages of export
  Isolate test files (#160)
  Deleted some temporary files that CLI tests were creating.
  Add python 3.7 to testsuite + udpate pypi creds
  ...
johnbergvall pushed a commit to johnbergvall/python-dotenv that referenced this pull request Aug 13, 2021
* Move parser to separate module

* Add tests

* Use unicode strings for unit tests in Python 2

Using `str` (e.g. `bytes`) is inconsistent with the types and the
implementation.

* Refactor parser

This fixes inconsistencies reported after the release of version 0.10.0:

* Valid escapes were interpreted as control characters even when in
  single-quoted strings.
* `#` was interpreted as the start of a comment even if there was no
  whitespace preceding it.

However, we are keeping the interpretation of escapes in double-quoted
strings as they didn't make sense in versions before 0.10.0.

The single large regular expression is replaced with a handwritten
top-down parser using smaller regular expressions.  The reason for this
change is that it would have been very difficult or impossible to
satisfy the parsing requirements with a single regex.
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.

Breaking changes in 0.10.0 and future changes
4 participants