Wrap all EventTiles with a TileErrorBoundary and guard parsePermalink (#7916)

Co-authored-by: Travis Ralston <travisr@matrix.org>
This commit is contained in:
Michael Telatynski 2022-03-01 08:41:48 +00:00 committed by GitHub
parent 08c47ac473
commit 16e67e7716
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 40 deletions

View file

@ -422,13 +422,17 @@ function getPermalinkConstructor(): PermalinkConstructor {
}
export function parsePermalink(fullUrl: string): PermalinkParts {
const elementPrefix = SdkConfig.get()['permalinkPrefix'];
if (decodeURIComponent(fullUrl).startsWith(matrixtoBaseUrl)) {
return new MatrixToPermalinkConstructor().parsePermalink(decodeURIComponent(fullUrl));
} else if (fullUrl.startsWith("matrix:")) {
return new MatrixSchemePermalinkConstructor().parsePermalink(fullUrl);
} else if (elementPrefix && fullUrl.startsWith(elementPrefix)) {
return new ElementPermalinkConstructor(elementPrefix).parsePermalink(fullUrl);
try {
const elementPrefix = SdkConfig.get()['permalinkPrefix'];
if (decodeURIComponent(fullUrl).startsWith(matrixtoBaseUrl)) {
return new MatrixToPermalinkConstructor().parsePermalink(decodeURIComponent(fullUrl));
} else if (fullUrl.startsWith("matrix:")) {
return new MatrixSchemePermalinkConstructor().parsePermalink(fullUrl);
} else if (elementPrefix && fullUrl.startsWith(elementPrefix)) {
return new ElementPermalinkConstructor(elementPrefix).parsePermalink(fullUrl);
}
} catch (e) {
logger.error("Failed to parse permalink", e);
}
return null; // not a permalink we can handle