Add suggestions for invalid URLs

This commit is contained in:
Danila Fedorin
2021-08-30 14:14:31 -07:00
parent 0844279c58
commit b57fbd8b6d
5 changed files with 71 additions and 5 deletions
+18
View File
@@ -71,6 +71,24 @@ export const LinkKind = createEnum(
"Event"
)
export function tryFixUrl(fragment) {
const attempts = [];
if (fragment.startsWith('#') && !fragment.startsWith('#/')) {
if (!fragment.match(/^#[@$!]/)) {
attempts.push('#/' + fragment); // #room => #/#room
}
attempts.push('#/' + fragment.substring(1)); // #@room => #/@room
}
const validAttempts = [];
for (const attempt of attempts) {
const link = Link.parse(attempt);
if (link) {
validAttempts.push({ url: attempt, link });
}
}
return validAttempts;
}
export class Link {
static validateIdentifier(identifier) {
return !!(