Language: Python
Label: safe
CWE: CWE-20 \u2014 Improper Input Validation
The product receives input or data, but it does
        not validate or incorrectly validates that the input has the
        properties that are required to process the data safely and
        correctly.

Code:
    def cast(self, typ, value):
        """
        cast value to given format.
        """
        if typ == "int":
            return int(value)

        elif typ == "float":
            return float(value)

        elif typ == "str":
            return "" if value is None else str(value)

        elif typ == "bytes":
            return b"" if value is None else bytes(value)

        elif typ == "bool":
            value = "" if value is None else str(value)
            return value.lower() in ("1", "true", "on", "yes", "y")

        elif typ == "time":
            default_value = "0:00"
            value = "" if value is None else str(value)
            if not value:
                value = default_value
            elif ":" not in value:
                value += ":00"

            hours, seconds = value.split(":", 1)
            if (
                hours.isnumeric()
                and seconds.isnumeric()
                and 0 <= int(hours) <= 23
                and 0 <= int(seconds) <= 59
            ):
                pass
            else:
                value = default_value

            return value

        elif typ in ("file", "folder"):
            return (
                ""
                if value in (None, "")
                else os.path.realpath(os.path.expanduser(os.fsdecode(value)))
            )

        else:
            return value