Skip to content
Snippets Groups Projects
Unverified Commit 27c74448 authored by Bruno Windels's avatar Bruno Windels Committed by GitHub
Browse files

Merge pull request #232 from matrix-org/bwindels/fix-parse-identifier

have a separate parse method for identifier so we don't validate the fragment hash
parents a460b52e b32b4b85
No related branches found
No related tags found
No related merge requests found
...@@ -80,7 +80,7 @@ export function tryFixUrl(fragment) { ...@@ -80,7 +80,7 @@ export function tryFixUrl(fragment) {
const validAttempts = []; const validAttempts = [];
for (const attempt of [...new Set(attempts)]) { for (const attempt of [...new Set(attempts)]) {
const link = Link.parse(attempt); const link = Link.parseFragment(attempt);
if (link) { if (link) {
validAttempts.push({ url: attempt, link }); validAttempts.push({ url: attempt, link });
} }
...@@ -98,11 +98,20 @@ export class Link { ...@@ -98,11 +98,20 @@ export class Link {
); );
} }
static parse(fragment) { static parseIdentifier(identifier) {
return Link._parse(identifier);
}
static parseFragment(fragment) {
if (!fragment) { if (!fragment) {
return null; return null;
} }
let [linkStr, queryParamsStr] = fragment.split("?"); let [linkStr, queryParamsStr] = fragment.split("?");
if (!linkStr.startsWith("#/")) {
return null;
}
linkStr = linkStr.substr(2);
const [identifier, eventId] = linkStr.split("/");
let viaServers = []; let viaServers = [];
let clientId = null; let clientId = null;
...@@ -121,14 +130,13 @@ export class Link { ...@@ -121,14 +130,13 @@ export class Link {
} }
webInstances = getWebInstanceMap(queryParams); webInstances = getWebInstanceMap(queryParams);
} }
return Link._parse(identifier, eventId, clientId, viaServers, webInstances);
}
if (!linkStr.startsWith("#/")) { static _parse(identifier, eventId = undefined, clientId = null, viaServers = [], webInstances = {}) {
if (!identifier) {
return null; return null;
} }
linkStr = linkStr.substr(2);
const [identifier, eventId] = linkStr.split("/");
let matches; let matches;
matches = USERID_PATTERN.exec(identifier); matches = USERID_PATTERN.exec(identifier);
if (matches) { if (matches) {
......
...@@ -76,7 +76,7 @@ export class RootViewModel extends ViewModel { ...@@ -76,7 +76,7 @@ export class RootViewModel extends ViewModel {
} else if (hash === "" || hash === "#" || hash === "#/") { } else if (hash === "" || hash === "#" || hash === "#/") {
this._updateChildVMs(null, oldLink); this._updateChildVMs(null, oldLink);
this.createLinkViewModel = new CreateLinkViewModel(this.childOptions()); this.createLinkViewModel = new CreateLinkViewModel(this.childOptions());
} else if (newLink = Link.parse(hash)) { } else if (newLink = Link.parseFragment(hash)) {
this._updateChildVMs(newLink, oldLink); this._updateChildVMs(newLink, oldLink);
} else { } else {
this._updateChildVMs(null, oldLink); this._updateChildVMs(null, oldLink);
......
...@@ -30,7 +30,7 @@ export class CreateLinkViewModel extends ViewModel { ...@@ -30,7 +30,7 @@ export class CreateLinkViewModel extends ViewModel {
} }
async createLink(identifier) { async createLink(identifier) {
this._link = Link.parse(identifier); this._link = Link.parseIdentifier(identifier);
if (this._link) { if (this._link) {
this.openLink("#" + this._link.toFragment()); this.openLink("#" + this._link.toFragment());
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment