summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorかっこかり <67428053+kakkokari-gtyih@users.noreply.github.com>2024-07-07 14:19:00 +0900
committerGitHub <noreply@github.com>2024-07-07 14:19:00 +0900
commit9ef6c4716ca25d8adeb5344c82a433370a086f88 (patch)
treeffd8e2a0ca63194afc2447692abd77238808fcb6
parentfeat(misskey-js): multipart/form-dataのリクエストに対応 (#14147) (diff)
downloadmisskey-9ef6c4716ca25d8adeb5344c82a433370a086f88.tar.gz
misskey-9ef6c4716ca25d8adeb5344c82a433370a086f88.tar.bz2
misskey-9ef6c4716ca25d8adeb5344c82a433370a086f88.zip
fix(backend): 名前を空白文字列だけにできる問題を修正 (#14119)
* fix(backend): 名前を空白文字列だけにできる問題を修正 * Update Changelog * fix test * Unicodeを含める * fix * ユーザー名がUnicode制御文字とスペースのみで構成される場合はnullに * Revert "ユーザー名がUnicode制御文字とスペースのみで構成される場合はnullに" This reverts commit 6c752a69c0d3649072e7e4ed30025183bceb48f9. * [ci skip] changelog typo
-rw-r--r--CHANGELOG.md2
-rw-r--r--packages/backend/src/server/api/endpoints/i/update.ts9
-rw-r--r--packages/backend/test/e2e/endpoints.ts13
3 files changed, 21 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 23de5957fd..f62f966451 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -29,6 +29,8 @@
- Fix: 自分以外のクリップ内のノート個数が見えることがあるのを修正
- Fix: 空文字列のリアクションはフォールバックされるように
- Fix: リノートにリアクションできないように
+- Fix: ユーザー名の前後に空白文字列がある場合は省略するように
+- Fix: プロフィール編集時に名前を空白文字列のみにできる問題を修正
### Misskey.js
- Feat: `/drive/files/create` のリクエストに対応(`multipart/form-data`に対応)
diff --git a/packages/backend/src/server/api/endpoints/i/update.ts b/packages/backend/src/server/api/endpoints/i/update.ts
index a8e702f328..b39b52bc41 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<typeof meta, typeof paramDef> { // 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/endpoints.ts b/packages/backend/test/e2e/endpoints.ts
index d5583ea8bb..2b2699ecd9 100644
--- a/packages/backend/test/e2e/endpoints.ts
+++ b/packages/backend/test/e2e/endpoints.ts
@@ -117,12 +117,21 @@ 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', {
+ // 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, 'あ い う');
});
test('誕生日の設定を削除できる', async () => {