Coverage for src/data_api/utils/schema.py: 100%
10 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-11-13 19:28 +0000
« prev ^ index » next coverage.py v7.16.2, created at 2026-11-13 19:28 +0000
1def url_corrector(url: object) -> object:
2 """
3 Fix the URL under different conditions:
4 If the URL starts with "//", prepend "https:" to it.
5 If the URL contains "://" but does not start with "http" or "https", prepend "https://" to it.
7 Args:
8 url (object): The value to validate, corrected only when it is a string.
10 Returns:
11 object: The fixed URL or the original non-string value for downstream validation.
12 """
13 if not isinstance(url, str):
14 return url
16 url = url.strip()
17 if url.startswith("//"):
18 return "https:" + url
19 else:
20 split_url = url.split("://")
21 if len(split_url) > 1 and split_url[0] not in ["http", "https"]:
22 return "https://" + split_url[1]
24 return url