From e2fb5de5951ab8fdece50f41de2fc87959869845 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Mon, 30 Aug 2021 14:39:56 -0700 Subject: [PATCH] Adjust fix suggestions --- src/Link.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/Link.js b/src/Link.js index 76bfa8a..9621e02 100644 --- a/src/Link.js +++ b/src/Link.js @@ -73,14 +73,13 @@ export const LinkKind = createEnum( 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 afterHash = fragment.substring(fragment.startsWith("#/") ? 2 : 1); + attempts.push('#/@' + afterHash); // #room => #/@room + attempts.push('#/#' + afterHash); // #@room => #/@room + attempts.push('#/!' + afterHash); // #@room => #/@room + const validAttempts = []; - for (const attempt of attempts) { + for (const attempt of [...new Set(attempts)]) { const link = Link.parse(attempt); if (link) { validAttempts.push({ url: attempt, link });