mirror of
https://github.com/sct/overseerr.git
synced 2025-12-27 08:45:06 +01:00
The isValidURL function was returning false when the provided value was undefined/null/empty, but needs to return true instead so it doesn't interfere with Yup validation.
18 lines
426 B
TypeScript
18 lines
426 B
TypeScript
export function isValidURL(value: unknown) {
|
|
try {
|
|
let url: URL;
|
|
if (value === undefined || value === null || value === '') {
|
|
return true;
|
|
} else if (typeof value === 'string') {
|
|
url = new URL(value);
|
|
} else if (value instanceof URL) {
|
|
url = value;
|
|
} else {
|
|
return false;
|
|
}
|
|
return url.protocol === 'http:' || url.protocol === 'https:';
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|