Skip to content

Commit 41d7308

Browse files
committed
have a separate parse method for identifier so we don't validate the fragment hash
1 parent a460b52 commit 41d7308

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

src/Link.js

+13-11
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export function tryFixUrl(fragment) {
8080

8181
const validAttempts = [];
8282
for (const attempt of [...new Set(attempts)]) {
83-
const link = Link.parse(attempt);
83+
const link = Link.parseFragment(attempt);
8484
if (link) {
8585
validAttempts.push({ url: attempt, link });
8686
}
@@ -98,11 +98,17 @@ export class Link {
9898
);
9999
}
100100

101-
static parse(fragment) {
102-
if (!fragment) {
101+
static parseIdentifier(identifier) {
102+
return Link._parse(identifier);
103+
}
104+
105+
static parseFragment(fragment) {
106+
let [linkStr, queryParamsStr] = fragment.split("?");
107+
if (!linkStr.startsWith("#/")) {
103108
return null;
104109
}
105-
let [linkStr, queryParamsStr] = fragment.split("?");
110+
linkStr = linkStr.substr(2);
111+
const [identifier, eventId] = linkStr.split("/");
106112

107113
let viaServers = [];
108114
let clientId = null;
@@ -121,14 +127,10 @@ export class Link {
121127
}
122128
webInstances = getWebInstanceMap(queryParams);
123129
}
130+
return Link._parse(identifier, eventId, clientId, viaServers, webInstances);
131+
}
124132

125-
if (!linkStr.startsWith("#/")) {
126-
return null;
127-
}
128-
linkStr = linkStr.substr(2);
129-
130-
const [identifier, eventId] = linkStr.split("/");
131-
133+
static _parse(identifier, eventId = undefined, clientId = null, viaServers = [], webInstances = {}) {
132134
let matches;
133135
matches = USERID_PATTERN.exec(identifier);
134136
if (matches) {

src/RootViewModel.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class RootViewModel extends ViewModel {
7676
} else if (hash === "" || hash === "#" || hash === "#/") {
7777
this._updateChildVMs(null, oldLink);
7878
this.createLinkViewModel = new CreateLinkViewModel(this.childOptions());
79-
} else if (newLink = Link.parse(hash)) {
79+
} else if (newLink = Link.parseFragment(hash)) {
8080
this._updateChildVMs(newLink, oldLink);
8181
} else {
8282
this._updateChildVMs(null, oldLink);

src/create/CreateLinkViewModel.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class CreateLinkViewModel extends ViewModel {
3030
}
3131

3232
async createLink(identifier) {
33-
this._link = Link.parse(identifier);
33+
this._link = Link.parseIdentifier(identifier);
3434
if (this._link) {
3535
this.openLink("#" + this._link.toFragment());
3636
}

0 commit comments

Comments
 (0)