From e010342c0ea490f907027fdcea9d8cb1a868a08c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=BE=E3=81=A3=E3=81=A1=E3=82=83=E3=81=A8=E3=83=BC?= =?UTF-8?q?=E3=81=AB=E3=82=85?= <17376330+u1-liquid@users.noreply.github.com> Date: Fri, 22 Mar 2024 19:05:05 +0900 Subject: [PATCH] =?UTF-8?q?enhance(frontend):=20=E5=A4=96=E9=83=A8?= =?UTF-8?q?=E3=82=B5=E3=82=A4=E3=83=88=E3=81=B8=E3=81=AE=E3=83=AA=E3=83=B3?= =?UTF-8?q?=E3=82=AF=E3=81=AF=E7=A7=BB=E5=8B=95=E3=81=AE=E8=AD=A6=E5=91=8A?= =?UTF-8?q?=E3=81=AE=E6=9D=A1=E4=BB=B6=E3=81=AE=E8=AA=BF=E6=95=B4=20(Missk?= =?UTF-8?q?eyIO#564)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit 65978cbe61b7e86e25795948ee2ef34bdf6f846c) --- locales/ja-JP.yml | 2 +- .../frontend/src/scripts/warning-external-website.ts | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml index e024d22b06..abb1cdea29 100644 --- a/locales/ja-JP.yml +++ b/locales/ja-JP.yml @@ -1200,7 +1200,7 @@ signupPendingError: "メールアドレスの確認中に問題が発生しま cwNotationRequired: "「内容を隠す」がオンの場合は注釈の記述が必要です。" doReaction: "リアクションする" wellKnownWebsites: "よく知られたウェブサイト" -wellKnownWebsitesDescription: "スペースで区切るとAND指定になり、改行で区切るとOR指定になります。スラッシュで囲むと正規表現になります。一致した場合、外部サイトへのリダイレクトの警告を省略させることができます。" +wellKnownWebsitesDescription: "スペースで区切るとAND指定になり、改行で区切るとOR指定になります。スラッシュで囲むと正規表現になります。ドメイン名だけ書くと後方一致になります。一致した場合、外部サイトへのリダイレクトの警告を省略させることができます。" code: "コード" reloadRequiredToApplySettings: "設定の反映にはリロードが必要です。" remainingN: "残り: {n}" diff --git a/packages/frontend/src/scripts/warning-external-website.ts b/packages/frontend/src/scripts/warning-external-website.ts index 08bb2b16e6..9cca2b925d 100644 --- a/packages/frontend/src/scripts/warning-external-website.ts +++ b/packages/frontend/src/scripts/warning-external-website.ts @@ -9,19 +9,20 @@ import { defaultStore } from '@/store.js'; import * as os from '@/os.js'; import MkUrlWarningDialog from '@/components/MkUrlWarningDialog.vue'; +const extractDomain = /^(https?:\/\/|\/\/)?([^@/\s]+@)?(www\.)?([^:/\s]+)/i; const isRegExp = /^\/(.+)\/(.*)$/; export async function warningExternalWebsite(ev: MouseEvent, url: string) { - const _url = new URL(url); - - const self = url.startsWith(local); + const domain = extractDomain.exec(url)?.[4]; + const self = !domain || url.startsWith(local); const isWellKnownWebsite = self || instance.wellKnownWebsites.some(expression => { const r = isRegExp.exec(expression); if (r) { return new RegExp(r[1], r[2]).test(url); - } else return expression.split(' ').every(keyword => url.includes(keyword)); + } else if (expression.includes(' ')) return expression.split(' ').every(keyword => url.includes(keyword)); + else return domain.endsWith(expression); }); - const isTrustedByUser = defaultStore.reactiveState.trustedDomains.value.includes(_url.hostname); + const isTrustedByUser = defaultStore.reactiveState.trustedDomains.value.includes(domain); if (!self && !isWellKnownWebsite && !isTrustedByUser) { ev.preventDefault();