Skip to content

fix some dotenv parsing #6987

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

Merged
merged 1 commit into from
Oct 4, 2022
Merged

fix some dotenv parsing #6987

merged 1 commit into from
Oct 4, 2022

Conversation

dhalbert
Copy link
Collaborator

@dhalbert dhalbert commented Oct 4, 2022

Fixes #6661.

This improves dotenv parsing, though there are probably still mistakes.

  • # in values immediately following = are included, instead of starting a comment. This is how such values are parsed in Unix shells.
  • #s inside single quote values now work properly.
  • key= with a blank value are now the empty string instead of None.
  • Character reading in dotenv was refactored a bit, and it's now 176 bytes smaller.
  • A manual test was included.

The syntax used for dotenv files is not well specified, and there are variations in how Python dotenv works compared with how shells work, mostly revolving around comment handling.

jepler
jepler previously approved these changes Oct 4, 2022
Copy link

@jepler jepler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I also ran the test and it seems OK. For backslashes inside single quotes it matches dotenv, but is different from (ba)sh, but that's OK. There's a way to enter a string containing literal ' and '#' characters now and that's great.

Copy link

@jepler jepler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@dhalbert dhalbert merged commit 1fd09cb into adafruit:main Oct 4, 2022
@dhalbert dhalbert deleted the dotenv-fixes branch October 4, 2022 12:00
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.

dotenv: minor difference from standard package
2 participants