Skip to content

Commit 8c1d04f

Browse files
committed
[core] fix controller.encodeUrl() encoding non http urls
1 parent 40a39bd commit 8c1d04f

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/controller/index.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,17 @@ export class ScramjetController {
9797
}
9898

9999
encodeUrl(url: string | URL): string {
100-
if (url instanceof URL) url = url.toString();
100+
if (typeof url === "string") url = new URL(url);
101+
102+
if (url.protocol != "http:" && url.protocol != "https:") {
103+
return url.href;
104+
}
105+
106+
const encodedHash = codecEncode(url.hash.slice(1));
107+
const realHash = encodedHash ? "#" + encodedHash : "";
108+
url.hash = "";
101109

102-
return config.prefix + codecEncode(url);
110+
return config.prefix + codecEncode(url.href) + realHash;
103111
}
104112

105113
decodeUrl(url: string | URL) {

0 commit comments

Comments
 (0)