Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions copier/_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ def cast_to_bool(value: Any) -> bool:
# Assume it's a number
with suppress(TypeError, ValueError):
return bool(float(value))

# Treat whitespace-only string as False
if isinstance(value,str) and not value.strip():
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
# Treat whitespace-only string as False
if isinstance(value,str) and not value.strip():
# Treat whitespace-only string as False
if isinstance(value, str) and not value.strip():

return False

# Assume it's a string
with suppress(AttributeError):
lower = value.lower()
Expand Down
8 changes: 8 additions & 0 deletions tests/test_cast_to_bool.py
Comment thread
developreiloyo marked this conversation as resolved.
Outdated
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from copier._tools import cast_to_bool


def test_cast_to_bool_whitespace_only_strings_are_false() -> None:
assert cast_to_bool("") is False
assert cast_to_bool(" ") is False
assert cast_to_bool("\n") is False
assert cast_to_bool(" \n\t") is False