Skip to content
Permalink
Browse files Browse the repository at this point in the history
validate time config values
  • Loading branch information
GammaC0de committed Jan 21, 2023
1 parent c602df5 commit a2b1eb1
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/pyload/core/config/parser.py
Expand Up @@ -279,15 +279,32 @@ def cast(self, typ, 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 = "0:00"
if ":" not in 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)))
return (
""
if value in (None, "")
else os.path.realpath(os.path.expanduser(os.fsdecode(value)))
)

else:
return value
Expand Down

0 comments on commit a2b1eb1

Please sign in to comment.