Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

fix(backend): strip whitespace in bool string conversion (#14486)

Soroush Ahmadi3c478d08bffc
diff --git a/autogpt_platform/backend/backend/util/type.py b/autogpt_platform/backend/backend/util/type.py
index ca49f61412..0f422c1e4d 100644
--- a/autogpt_platform/backend/backend/util/type.py
+++ b/autogpt_platform/backend/backend/util/type.py
@@ -104,7 +104,7 @@ def __convert_bool(value: Any) -> bool:
if isinstance(value, bool):
return value
elif isinstance(value, str):
- if value.lower() in ["true", "1"]:
+ if value.strip().lower() in ["true", "1"]:
return True
else:
return False
diff --git a/autogpt_platform/backend/backend/util/type_test.py b/autogpt_platform/backend/backend/util/type_test.py
index ea25270511..90b2b2bf5a 100644
--- a/autogpt_platform/backend/backend/util/type_test.py
+++ b/autogpt_platform/backend/backend/util/type_test.py
@@ -17,6 +17,9 @@ def test_type_conversion():
assert convert("True", bool) is True
assert convert("False", bool) is False
+ assert convert(" true ", bool) is True
+ assert convert("1 ", bool) is True
+ assert convert(" false ", bool) is False
assert convert(5, str) == "5"
assert convert({"a": 1, "b": 2}, str) == '{"a": 1, "b": 2}'