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 { // 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 3458e06384..5fb9642367 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())); });