Skip to content

Commit 23a378e

Browse files
committed
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.
1 parent 45626c4 commit 23a378e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/utils/helpers.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ export function throwUnsupported(instance: object) {
66

77
export function isValidUrl(str: string) {
88
try {
9-
new URL(str);
10-
return true;
9+
const url = new URL(str);
10+
return url.protocol === "http" || url.protocol === "https";
1111
} catch (_) {
1212
return false;
1313
}

0 commit comments

Comments
 (0)