From 88838f2704ee148c24e65dadeef59a70850521a2 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Mon, 20 May 2024 23:15:47 +0900 Subject: [PATCH 1/2] fix: `/share` with unicode characters in the URL --- packages/frontend/src/pages/share.vue | 29 ++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/packages/frontend/src/pages/share.vue b/packages/frontend/src/pages/share.vue index 680934e7ce78..37f6558d6432 100644 --- a/packages/frontend/src/pages/share.vue +++ b/packages/frontend/src/pages/share.vue @@ -64,7 +64,34 @@ async function init() { // Googleニュース対策 if (text?.startsWith(`${title.value}.\n`)) noteText += text.replace(`${title.value}.\n`, ''); else if (text && title.value !== text) noteText += `${text}\n`; - if (url) noteText += `${url}`; + if (url) { + try { + // Normalize the URL to URL-encoded and puny-coded from with the URL constructor. + // + // It's common to use unicode characters in the URL for better visibility of URL + // like: https://ja.wikipedia.org/wiki/ミスキー + // or like: https://藍.moe/ + // However, in the MFM, the unicode characters must be URL-encoded to be parsed as `url` node + // like: https://ja.wikipedia.org/wiki/%E3%83%9F%E3%82%B9%E3%82%AD%E3%83%BC + // or like: https://xn--931a.moe/ + // Therefore, we need to normalize the URL to URL-encoded form. + // + // The URL constructor will parse the URL and normalize unicode characters + // in the host to punycode and in the path component to URL-encoded form. + // (see url.spec.whatwg.org) + // + // In addition, the current MFM renderer decodes the URL-encoded path and / punycode encoded host name so + // this normalization doesn't make the visible URL ugly. + // (see MkUrl.vue) + + noteText += new URL(url).href; + } catch { + // fallback to original URL if the URL is invalid. + // note that this is extremely rare since the `url` parameter is designed to share a URL and + // the URL constructor will throw TypeError only if failure, which means the URL is not valid. + noteText += url; + } + } initialText.value = noteText.trim(); if (visibility.value === 'specified') { From abdc3bd25d158473c8c8e0a4dc833a853609de00 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Mon, 20 May 2024 23:17:34 +0900 Subject: [PATCH 2/2] =?UTF-8?q?docs(changelog):=20`/share`=20=E3=81=A7?= =?UTF-8?q?=E6=97=A5=E6=9C=AC=E8=AA=9E=E7=AD=89=E3=82=92=E5=90=AB=E3=82=80?= =?UTF-8?q?url=E3=81=8Curl=E3=82=A8=E3=83=B3=E3=82=B3=E3=83=BC=E3=83=89?= =?UTF-8?q?=E3=81=95=E3=82=8C=E3=81=AA=E3=81=84=E5=95=8F=E9=A1=8C=E3=82=92?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a9944d4b5eaa..8d1b0a010a3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -60,6 +60,7 @@ - Fix: リバーシの対局を正しく共有できないことがある問題を修正 - Fix: 通知をグループ化している際に、人数が正常に表示されないことがある問題を修正 - Fix: 連合なしの状態の読み書きができない問題を修正 +- Fix: `/share` で日本語等を含むurlがurlエンコードされない問題を修正 ### Server - Enhance: エンドポイント`antennas/update`の必須項目を`antennaId`のみに