Files
sct-overseerr/src/utils/urlValidationHelper.ts
Gauthier d226dbb9b4 fix(url validation): correct URL validation for empty fields (#1657)
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.
2025-05-12 16:18:34 +08:00

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;
}
}