From df4a63812e1b4987147596fdaf271f86d815f925 Mon Sep 17 00:00:00 2001 From: kakkokari-gtyih <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Tue, 2 Jul 2024 18:37:33 +0900 Subject: [PATCH 1/8] =?UTF-8?q?fix(backend):=20=E5=90=8D=E5=89=8D=E3=82=92?= =?UTF-8?q?=E7=A9=BA=E7=99=BD=E6=96=87=E5=AD=97=E5=88=97=E3=81=A0=E3=81=91?= =?UTF-8?q?=E3=81=AB=E3=81=A7=E3=81=8D=E3=82=8B=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 --- packages/backend/src/server/api/endpoints/i/update.ts | 9 ++++++++- packages/backend/test/e2e/users.ts | 7 +++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/i/update.ts b/packages/backend/src/server/api/endpoints/i/update.ts index a8e702f328e6..b39b52bc4148 100644 --- a/packages/backend/src/server/api/endpoints/i/update.ts +++ b/packages/backend/src/server/api/endpoints/i/update.ts @@ -257,7 +257,14 @@ export default class extends Endpoint { // eslint- const profile = await this.userProfilesRepository.findOneByOrFail({ userId: user.id }); - if (ps.name !== undefined) updates.name = ps.name; + if (ps.name !== undefined) { + if (ps.name === null) { + updates.name = null; + } else { + const trimmedName = ps.name.trim(); + updates.name = trimmedName === '' ? null : trimmedName; + } + } if (ps.description !== undefined) profileUpdates.description = ps.description; if (ps.lang !== undefined) profileUpdates.lang = ps.lang; if (ps.location !== undefined) profileUpdates.location = ps.location; diff --git a/packages/backend/test/e2e/users.ts b/packages/backend/test/e2e/users.ts index 3458e06384f2..5fb9642367df 100644 --- a/packages/backend/test/e2e/users.ts +++ b/packages/backend/test/e2e/users.ts @@ -409,6 +409,9 @@ describe('ユーザー', () => { { parameters: () => ({ name: 'x'.repeat(50) }) }, { parameters: () => ({ name: 'x' }) }, { parameters: () => ({ name: 'My name' }) }, + { parameters: () => ({ name: '' }), expect: { name: null } }, + { parameters: () => ({ name: ' name with spaces ' }), expect: { name: 'name with spaces' } }, + { parameters: () => ({ name: ' ' }), expect: { name: null } }, { parameters: () => ({ description: null }) }, { parameters: () => ({ description: 'x'.repeat(1500) }) }, { parameters: () => ({ description: 'x' }) }, @@ -465,9 +468,9 @@ describe('ユーザー', () => { { parameters: () => ({ notificationRecieveConfig: {} }) }, { parameters: () => ({ emailNotificationTypes: ['mention', 'reply', 'quote', 'follow', 'receiveFollowRequest'] }) }, { parameters: () => ({ emailNotificationTypes: [] }) }, - ] as const)('を書き換えることができる($#)', async ({ parameters }) => { + ] as const)('を書き換えることができる($#)', async ({ parameters, expect }) => { const response = await successfulApiCall({ endpoint: 'i/update', parameters: parameters(), user: alice }); - const expected = { ...meDetailed(alice, true), ...parameters() }; + const expected = { ...meDetailed(alice, true), ...parameters(), ...expect }; assert.deepStrictEqual(response, expected, inspect(parameters())); }); From 646750cd98f785f3b63692f0de455a40e309a42d Mon Sep 17 00:00:00 2001 From: kakkokari-gtyih <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Tue, 2 Jul 2024 18:38:38 +0900 Subject: [PATCH 2/8] Update Changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a28c9ef640a..32aff670de94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,8 @@ - Fix: 自分以外のクリップ内のノート個数が見えることがあるのを修正 - Fix: 空文字列のリアクションはフォールバックされるように - Fix: リノートにリアクションできないように +- Fix: ユーザー名の前後にスペースがある場合は省略するように +- Fix: プロフィール編集時に名前を空白文字列のみにできる問題を修正 ## 2024.5.0 From 70fe3574a82219f5cd8347a1db8a454fe085505c Mon Sep 17 00:00:00 2001 From: kakkokari-gtyih <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Tue, 2 Jul 2024 18:44:57 +0900 Subject: [PATCH 3/8] fix test --- packages/backend/test/e2e/endpoints.ts | 12 ++++++++++-- packages/backend/test/e2e/users.ts | 7 ++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/backend/test/e2e/endpoints.ts b/packages/backend/test/e2e/endpoints.ts index de5e8ba95e34..d3861051b57d 100644 --- a/packages/backend/test/e2e/endpoints.ts +++ b/packages/backend/test/e2e/endpoints.ts @@ -117,12 +117,20 @@ describe('Endpoints', () => { assert.strictEqual(res.body.birthday, myBirthday); }); - test('名前を空白にできる', async () => { + test('名前を空白のみにした場合nullになる', async () => { const res = await api('i/update', { name: ' ', }, alice); assert.strictEqual(res.status, 200); - assert.strictEqual(res.body.name, ' '); + assert.strictEqual(res.body.name, null); + }); + + test('名前の前後に空白を入れてもトリムされる', async () => { + const res = await api('i/update', { + name: ' あ い う ', + }, alice); + assert.strictEqual(res.status, 200); + assert.strictEqual(res.body.name, 'あ い う'); }); test('誕生日の設定を削除できる', async () => { diff --git a/packages/backend/test/e2e/users.ts b/packages/backend/test/e2e/users.ts index 5fb9642367df..3458e06384f2 100644 --- a/packages/backend/test/e2e/users.ts +++ b/packages/backend/test/e2e/users.ts @@ -409,9 +409,6 @@ describe('ユーザー', () => { { parameters: () => ({ name: 'x'.repeat(50) }) }, { parameters: () => ({ name: 'x' }) }, { parameters: () => ({ name: 'My name' }) }, - { parameters: () => ({ name: '' }), expect: { name: null } }, - { parameters: () => ({ name: ' name with spaces ' }), expect: { name: 'name with spaces' } }, - { parameters: () => ({ name: ' ' }), expect: { name: null } }, { parameters: () => ({ description: null }) }, { parameters: () => ({ description: 'x'.repeat(1500) }) }, { parameters: () => ({ description: 'x' }) }, @@ -468,9 +465,9 @@ describe('ユーザー', () => { { parameters: () => ({ notificationRecieveConfig: {} }) }, { parameters: () => ({ emailNotificationTypes: ['mention', 'reply', 'quote', 'follow', 'receiveFollowRequest'] }) }, { parameters: () => ({ emailNotificationTypes: [] }) }, - ] as const)('を書き換えることができる($#)', async ({ parameters, expect }) => { + ] as const)('を書き換えることができる($#)', async ({ parameters }) => { const response = await successfulApiCall({ endpoint: 'i/update', parameters: parameters(), user: alice }); - const expected = { ...meDetailed(alice, true), ...parameters(), ...expect }; + const expected = { ...meDetailed(alice, true), ...parameters() }; assert.deepStrictEqual(response, expected, inspect(parameters())); }); From a5100253717b9baf527e9ad0b2a427a68df1b28b Mon Sep 17 00:00:00 2001 From: kakkokari-gtyih <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Tue, 2 Jul 2024 18:47:01 +0900 Subject: [PATCH 4/8] =?UTF-8?q?Unicode=E3=82=92=E5=90=AB=E3=82=81=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/backend/test/e2e/endpoints.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/backend/test/e2e/endpoints.ts b/packages/backend/test/e2e/endpoints.ts index d3861051b57d..2e38800875cd 100644 --- a/packages/backend/test/e2e/endpoints.ts +++ b/packages/backend/test/e2e/endpoints.ts @@ -125,9 +125,9 @@ describe('Endpoints', () => { assert.strictEqual(res.body.name, null); }); - test('名前の前後に空白を入れてもトリムされる', async () => { + test('名前の前後に空白(Unicodeのホワイトスペース)を入れてもトリムされる', async () => { const res = await api('i/update', { - name: ' あ い う ', + name: ' あ い う \u0020\u00a0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000', }, alice); assert.strictEqual(res.status, 200); assert.strictEqual(res.body.name, 'あ い う'); From b0a47c1c517a644a88f833a23d89d5693d66341e Mon Sep 17 00:00:00 2001 From: kakkokari-gtyih <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Tue, 2 Jul 2024 18:49:06 +0900 Subject: [PATCH 5/8] fix --- packages/backend/test/e2e/endpoints.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/backend/test/e2e/endpoints.ts b/packages/backend/test/e2e/endpoints.ts index 2e38800875cd..2b101fdbe7a0 100644 --- a/packages/backend/test/e2e/endpoints.ts +++ b/packages/backend/test/e2e/endpoints.ts @@ -125,9 +125,10 @@ describe('Endpoints', () => { assert.strictEqual(res.body.name, null); }); - test('名前の前後に空白(Unicodeのホワイトスペース)を入れてもトリムされる', async () => { + test('名前の前後に空白(ホワイトスペース)を入れてもトリムされる', async () => { const res = await api('i/update', { - name: ' あ い う \u0020\u00a0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000', + // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#white_space + name: ' あ い う \u0009\u000b\u000c\u0020\u00a0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\ufeff', }, alice); assert.strictEqual(res.status, 200); assert.strictEqual(res.body.name, 'あ い う'); From 6c752a69c0d3649072e7e4ed30025183bceb48f9 Mon Sep 17 00:00:00 2001 From: kakkokari-gtyih <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Tue, 2 Jul 2024 19:05:38 +0900 Subject: [PATCH 6/8] =?UTF-8?q?=E3=83=A6=E3=83=BC=E3=82=B6=E3=83=BC?= =?UTF-8?q?=E5=90=8D=E3=81=8CUnicode=E5=88=B6=E5=BE=A1=E6=96=87=E5=AD=97?= =?UTF-8?q?=E3=81=A8=E3=82=B9=E3=83=9A=E3=83=BC=E3=82=B9=E3=81=AE=E3=81=BF?= =?UTF-8?q?=E3=81=A7=E6=A7=8B=E6=88=90=E3=81=95=E3=82=8C=E3=82=8B=E5=A0=B4?= =?UTF-8?q?=E5=90=88=E3=81=AFnull=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/backend/src/server/api/endpoints/i/update.ts | 10 +++++++++- packages/backend/test/e2e/endpoints.ts | 8 ++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/server/api/endpoints/i/update.ts b/packages/backend/src/server/api/endpoints/i/update.ts index b39b52bc4148..e363b05625c9 100644 --- a/packages/backend/src/server/api/endpoints/i/update.ts +++ b/packages/backend/src/server/api/endpoints/i/update.ts @@ -252,6 +252,8 @@ export default class extends Endpoint { // eslint- const user = await this.usersRepository.findOneByOrFail({ id: _user.id }) as MiLocalUser; const isSecure = token == null; + const onlyControlCharsAndSpaceRegex = /^[\u0000-\u001F\u007F-\u009F\u061C\u200E\u200F\u202A-\u202E\u2066-\u2069\s]+$/; + const updates = {} as Partial; const profileUpdates = {} as Partial; @@ -262,7 +264,13 @@ export default class extends Endpoint { // eslint- updates.name = null; } else { const trimmedName = ps.name.trim(); - updates.name = trimmedName === '' ? null : trimmedName; + if (trimmedName === '') { + updates.name = null; + } else if (onlyControlCharsAndSpaceRegex.test(trimmedName)) { + updates.name = null; + } else { + updates.name = trimmedName; + } } } if (ps.description !== undefined) profileUpdates.description = ps.description; diff --git a/packages/backend/test/e2e/endpoints.ts b/packages/backend/test/e2e/endpoints.ts index 2b101fdbe7a0..f01fdf1d00c5 100644 --- a/packages/backend/test/e2e/endpoints.ts +++ b/packages/backend/test/e2e/endpoints.ts @@ -134,6 +134,14 @@ describe('Endpoints', () => { assert.strictEqual(res.body.name, 'あ い う'); }); + test('名前にUnicode制御文字とスペースしか含まない場合はnullになる', async () => { + const res = await api('i/update', { + name: ' \u202e ', + }, alice); + assert.strictEqual(res.status, 200); + assert.strictEqual(res.body.name, null); + }); + test('誕生日の設定を削除できる', async () => { await api('i/update', { birthday: '2000-09-07', From 38eb06f91fb4b1888682a37e7c9b54b1593c6b8b Mon Sep 17 00:00:00 2001 From: kakkokari-gtyih <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Tue, 2 Jul 2024 19:12:10 +0900 Subject: [PATCH 7/8] =?UTF-8?q?Revert=20"=E3=83=A6=E3=83=BC=E3=82=B6?= =?UTF-8?q?=E3=83=BC=E5=90=8D=E3=81=8CUnicode=E5=88=B6=E5=BE=A1=E6=96=87?= =?UTF-8?q?=E5=AD=97=E3=81=A8=E3=82=B9=E3=83=9A=E3=83=BC=E3=82=B9=E3=81=AE?= =?UTF-8?q?=E3=81=BF=E3=81=A7=E6=A7=8B=E6=88=90=E3=81=95=E3=82=8C=E3=82=8B?= =?UTF-8?q?=E5=A0=B4=E5=90=88=E3=81=AFnull=E3=81=AB"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 6c752a69c0d3649072e7e4ed30025183bceb48f9. --- packages/backend/src/server/api/endpoints/i/update.ts | 10 +--------- packages/backend/test/e2e/endpoints.ts | 8 -------- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/i/update.ts b/packages/backend/src/server/api/endpoints/i/update.ts index e363b05625c9..b39b52bc4148 100644 --- a/packages/backend/src/server/api/endpoints/i/update.ts +++ b/packages/backend/src/server/api/endpoints/i/update.ts @@ -252,8 +252,6 @@ export default class extends Endpoint { // eslint- const user = await this.usersRepository.findOneByOrFail({ id: _user.id }) as MiLocalUser; const isSecure = token == null; - const onlyControlCharsAndSpaceRegex = /^[\u0000-\u001F\u007F-\u009F\u061C\u200E\u200F\u202A-\u202E\u2066-\u2069\s]+$/; - const updates = {} as Partial; const profileUpdates = {} as Partial; @@ -264,13 +262,7 @@ export default class extends Endpoint { // eslint- updates.name = null; } else { const trimmedName = ps.name.trim(); - if (trimmedName === '') { - updates.name = null; - } else if (onlyControlCharsAndSpaceRegex.test(trimmedName)) { - updates.name = null; - } else { - updates.name = trimmedName; - } + updates.name = trimmedName === '' ? null : trimmedName; } } if (ps.description !== undefined) profileUpdates.description = ps.description; diff --git a/packages/backend/test/e2e/endpoints.ts b/packages/backend/test/e2e/endpoints.ts index f01fdf1d00c5..2b101fdbe7a0 100644 --- a/packages/backend/test/e2e/endpoints.ts +++ b/packages/backend/test/e2e/endpoints.ts @@ -134,14 +134,6 @@ describe('Endpoints', () => { assert.strictEqual(res.body.name, 'あ い う'); }); - test('名前にUnicode制御文字とスペースしか含まない場合はnullになる', async () => { - const res = await api('i/update', { - name: ' \u202e ', - }, alice); - assert.strictEqual(res.status, 200); - assert.strictEqual(res.body.name, null); - }); - test('誕生日の設定を削除できる', async () => { await api('i/update', { birthday: '2000-09-07', From d6fe9983057a5b24b06c65ee0722ef970a48423a Mon Sep 17 00:00:00 2001 From: kakkokari-gtyih <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Tue, 2 Jul 2024 19:15:36 +0900 Subject: [PATCH 8/8] [ci skip] changelog typo --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 32aff670de94..45ed4c1e40b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,7 +29,7 @@ - Fix: 自分以外のクリップ内のノート個数が見えることがあるのを修正 - Fix: 空文字列のリアクションはフォールバックされるように - Fix: リノートにリアクションできないように -- Fix: ユーザー名の前後にスペースがある場合は省略するように +- Fix: ユーザー名の前後に空白文字列がある場合は省略するように - Fix: プロフィール編集時に名前を空白文字列のみにできる問題を修正 ## 2024.5.0