From 23a378ebf3ab1c99338e365b73b55eeab96b9c61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Kr=C3=B6hnke?= Date: Thu, 14 Oct 2021 14:49:15 +0900 Subject: [PATCH] Fix `Image.src` on Windows when it is a local file `new URL("C:\path\filename.png")` is treated as a valid URL, which it is not. `phin` subsequently tries to fetch it, but `phin` and `centra` only supports http and https anyway. Therefore `isValidUrl` will check also the protocol. --- src/utils/helpers.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/helpers.ts b/src/utils/helpers.ts index f06859c3..d8537c5a 100644 --- a/src/utils/helpers.ts +++ b/src/utils/helpers.ts @@ -6,8 +6,8 @@ export function throwUnsupported(instance: object) { export function isValidUrl(str: string) { try { - new URL(str); - return true; + const url = new URL(str); + return url.protocol === "http" || url.protocol === "https"; } catch (_) { return false; }