Skip to content

Commit

Permalink
Merge pull request #405 from jnm/stricter-check-for-none-default-value
Browse files Browse the repository at this point in the history
Skip parsing only when `default=None`, not for all default values that coerce to `False`
  • Loading branch information
sergeyklay committed Jul 7, 2022
2 parents 9c201d4 + 3c1594a commit 64813ed
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion environ/environ.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ def get_value(self, var, cast=None, default=NOTSET, parse_default=False):

value = None if default is None and value == '' else value

if value != default or (parse_default and value):
if value != default or (parse_default and value is not None):
value = self.parse_value(value, cast)

return value
Expand Down
7 changes: 7 additions & 0 deletions tests/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,13 @@ def test_url_value(self):
assert url.geturl() == FakeEnv.URL
assert self.env.url('OTHER_URL', default=None) is None

def test_url_empty_string_default_value(self):
unset_var_name = 'VARIABLE_NOT_SET_IN_ENVIRONMENT'
assert unset_var_name not in os.environ
url = self.env.url(unset_var_name, '')
assert url.__class__ == self.env.URL_CLASS
assert url.geturl() == ''

def test_url_encoded_parts(self):
password_with_unquoted_characters = "#password"
encoded_url = "mysql://user:%s@127.0.0.1:3306/dbname" % quote(
Expand Down

0 comments on commit 64813ed

Please sign in to comment.