Skip to content

Commit

Permalink
Merge pull request #150 from iurisilvio/fix-csv-none
Browse files Browse the repository at this point in the history
Fixed #149 Csv with None should return an empty list.
  • Loading branch information
iurisilvio authored Jan 9, 2023
2 parents 39d70aa + afa46b1 commit f9a7a15
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions decouple.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ def __init__(self, cast=text_type, delimiter=',', strip=string.whitespace, post_

def __call__(self, value):
"""The actual transformation"""
if value is None:
return self.post_process()

transform = lambda s: self.cast(s.strip(self.strip))

splitter = shlex(value, posix=True)
Expand Down
5 changes: 5 additions & 0 deletions tests/test_helper_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,8 @@ def test_csv_quoted_parse():
assert ['foo', "'bar, baz'", "'qux"] == csv(''' foo ,"'bar, baz'", "'qux"''')

assert ['foo', '"bar, baz"', '"qux'] == csv(""" foo ,'"bar, baz"', '"qux'""")


def test_csv_none():
csv = Csv()
assert [] == csv(None)

0 comments on commit f9a7a15

Please sign in to comment.