diff options
author | Andreas Maier <andreas.r.maier@gmx.de> | 2020-06-28 22:12:57 +0200 |
---|---|---|
committer | David Lord <davidism@gmail.com> | 2020-10-10 17:45:02 -0700 |
commit | 0c1f7f096a3399d50da22856890f1e42b365344a (patch) | |
tree | f9a5de2c02981911a63ab42fee33b469b42d4012 /src/click/types.py | |
parent | a11a5da0a8459f4098ec884b7cc52534336856db (diff) | |
download | click-0c1f7f096a3399d50da22856890f1e42b365344a.tar.gz |
boolean type strips space before converting
Diffstat (limited to 'src/click/types.py')
-rw-r--r-- | src/click/types.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/click/types.py b/src/click/types.py index b7161d9..721c556 100644 --- a/src/click/types.py +++ b/src/click/types.py @@ -497,11 +497,15 @@ class BoolParamType(ParamType): def convert(self, value, param, ctx): if isinstance(value, bool): return bool(value) - value = value.lower() - if value in {"1", "true", "t", "yes", "y", "on"}: + + norm = value.strip().lower() + + if norm in {"1", "true", "t", "yes", "y", "on"}: return True - elif value in {"0", "false", "f", "no", "n", "off"}: + + if norm in {"0", "false", "f", "no", "n", "off"}: return False + self.fail(f"{value!r} is not a valid boolean value.", param, ctx) def __repr__(self): |