Skip to content

Commit bf4edf9

Browse files
committed
fix(url): ensure url is resolvable
1 parent 45bcd17 commit bf4edf9

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lib/util/url.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,17 @@ export function resolve(from: string, to: string) {
4545
*/
4646
export function cwd() {
4747
if (typeof window !== "undefined" && window.location && window.location.href) {
48-
return window.location.href;
48+
const href = window.location.href;
49+
if (!href || !href.startsWith("http")) {
50+
// try parsing as url, and if it fails, return root url /
51+
try {
52+
new URL(href);
53+
return href;
54+
} catch {
55+
return "/";
56+
}
57+
}
58+
return href;
4959
}
5060

5161
if (typeof process !== "undefined" && process.cwd) {

0 commit comments

Comments
 (0)