summaryrefslogtreecommitdiff
path: root/source/github-helpers/github-url.ts
diff options
context:
space:
mode:
authorGravatar Flo Edelmann <florian-edelmann@online.de> 2020-06-11 11:21:13 +0200
committerGravatar GitHub <noreply@github.com> 2020-06-11 11:21:13 +0200
commit68e3b074006864260f35a13fa2bc3cc0151de305 (patch)
tree72eb773478deab905556da36238d83213a427926 /source/github-helpers/github-url.ts
parente5c50bddc33a65407d7802c2007b02448e1fd0a9 (diff)
downloadrefined-github-68e3b074006864260f35a13fa2bc3cc0151de305.tar.gz
refined-github-68e3b074006864260f35a13fa2bc3cc0151de305.tar.zst
refined-github-68e3b074006864260f35a13fa2bc3cc0151de305.zip
Fix URL parsing in Firefox (#3208)
Co-authored-by: Federico Brigante <opensource@bfred.it>
Diffstat (limited to 'source/github-helpers/github-url.ts')
-rw-r--r--source/github-helpers/github-url.ts43
1 files changed, 38 insertions, 5 deletions
diff --git a/source/github-helpers/github-url.ts b/source/github-helpers/github-url.ts
index 139bf1a3..1966ee2a 100644
--- a/source/github-helpers/github-url.ts
+++ b/source/github-helpers/github-url.ts
@@ -1,6 +1,6 @@
import {getCurrentBranch} from '.';
-export default class GitHubURL extends URL {
+export default class GitHubURL {
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/26792
user: string;
// @ts-expect-error
@@ -14,15 +14,22 @@ export default class GitHubURL extends URL {
assign = Object.assign.bind(null, this);
+ private internalUrl: URL;
+
constructor(url: string) {
- super(url);
- this.pathname = super.pathname;
+ // Use Facade pattern instead of inheritance #3193
+ this.internalUrl = new URL(url);
+ this.pathname = this.internalUrl.pathname;
}
toString() {
return this.href;
}
+ toJSON() {
+ return this.href;
+ }
+
private disambiguateReference(ambiguousReference: string[]): {branch: string; filePath: string} {
const branch = ambiguousReference[0];
const filePathFromSearch = this.searchParams.getAll('path[]').join('/');
@@ -68,7 +75,33 @@ export default class GitHubURL extends URL {
get href() {
// Update the actual underlying URL
- super.pathname = this.pathname;
- return super.href;
+ this.internalUrl.pathname = this.pathname;
+ return this.internalUrl.href;
+ }
+
+ set href(href) {
+ this.internalUrl.href = href;
+ }
+
+ // Proxy all other getters/setters to internalUrl
+
+ get hash(): string {
+ return this.internalUrl.hash;
+ }
+
+ set hash(hash) {
+ this.internalUrl.hash = hash;
+ }
+
+ get search(): string {
+ return this.internalUrl.search;
+ }
+
+ set search(search) {
+ this.internalUrl.search = search;
+ }
+
+ get searchParams(): URLSearchParams {
+ return this.internalUrl.searchParams;
}
}