rusackas commented on code in PR #45768:
URL: https://github.com/apache/superset/pull/45768#discussion_r4386200752


##########
superset/extensions/storage/api.py:
##########
@@ -187,7 +188,7 @@ def get_ephemeral(
         if not extension:
             return self.response_404("Extension not found")
 
-        shared = request.args.get("shared", "false").lower() == "true"
+        shared = is_truthy_str(request.args.get("shared", "false"))

Review Comment:
   Good catch @sadpandajoe, dropped the `.strip()` so these call sites keep 
exact `.lower() == "true"` matching (d23ccc2).



##########
superset/utils/core.py:
##########
@@ -2245,6 +2245,41 @@ def parse_boolean_string(bool_str: str | None) -> bool:
     return bool_str.lower() in ("y", "Y", "yes", "True", "t", "true", "On", 
"on", "1")
 
 
+def is_truthy_str(value: str | None, default: bool = False) -> bool:
+    """
+    Case-insensitive match against the literal string "true", nothing else.
+
+    Unlike `parse_boolean_string`, this does not treat "yes"/"y"/"t"/"on"/"1"
+    as true -- it exists to de-duplicate several call sites that already had
+    this exact narrow semantics (e.g. `value.lower() == "true"`), without
+    silently widening what they accept.
+
+    >>> is_truthy_str(None)
+    False
+    >>> is_truthy_str(None, default=True)
+    True
+    >>> is_truthy_str('true')
+    True
+    >>> is_truthy_str('True')
+    True
+    >>> is_truthy_str('TRUE')
+    True
+    >>> is_truthy_str('false')
+    False
+    >>> is_truthy_str('1')
+    False
+    >>> is_truthy_str('yes')
+    False
+
+    :param value: string representation of a value assumed to be boolean
+    :param default: value to return when `value` is `None`
+    :return: strictly parsed boolean value
+    """
+    if value is None:
+        return default
+    return value.strip().lower() == "true"

Review Comment:
   Fixed, `is_truthy_str` no longer strips, so padded values stay false as 
before.



##########
tests/unit_tests/utils/test_core.py:
##########
@@ -210,6 +211,33 @@ def test_parse_boolean_string(test_input: Optional[str], 
expected: bool):
     assert parse_boolean_string(test_input) == expected
 
 
[email protected](
+    "test_input,expected",
+    [
+        ("true", True),
+        ("True", True),
+        ("TRUE", True),
+        ("false", False),
+        ("False", False),
+        ("foo", False),
+        # Unlike `parse_boolean_string`, these must NOT be treated as true.
+        ("1", False),
+        ("yes", False),
+        ("y", False),
+        ("t", False),
+        ("on", False),

Review Comment:
   Dropped the `.strip()` and added `" true "`, `"true "` and a 
tab/newline-padded `"true"` as `False` cases in the parametrized test.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to