Language: Python
Label: vulnerable
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":
            value = "" if value is None else str(value)
            if not value:
                value = "0:00"
            if ":" not in value:
                value += ":00"
            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