Skip to content

Commit 6c752a6

Browse files
ユーザー名がUnicode制御文字とスペースのみで構成される場合はnullに
1 parent b0a47c1 commit 6c752a6

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

packages/backend/src/server/api/endpoints/i/update.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
252252
const user = await this.usersRepository.findOneByOrFail({ id: _user.id }) as MiLocalUser;
253253
const isSecure = token == null;
254254

255+
const onlyControlCharsAndSpaceRegex = /^[\u0000-\u001F\u007F-\u009F\u061C\u200E\u200F\u202A-\u202E\u2066-\u2069\s]+$/;
256+
255257
const updates = {} as Partial<MiUser>;
256258
const profileUpdates = {} as Partial<MiUserProfile>;
257259

@@ -262,7 +264,13 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
262264
updates.name = null;
263265
} else {
264266
const trimmedName = ps.name.trim();
265-
updates.name = trimmedName === '' ? null : trimmedName;
267+
if (trimmedName === '') {
268+
updates.name = null;
269+
} else if (onlyControlCharsAndSpaceRegex.test(trimmedName)) {
270+
updates.name = null;
271+
} else {
272+
updates.name = trimmedName;
273+
}
266274
}
267275
}
268276
if (ps.description !== undefined) profileUpdates.description = ps.description;

packages/backend/test/e2e/endpoints.ts

+8
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,14 @@ describe('Endpoints', () => {
134134
assert.strictEqual(res.body.name, 'あ い う');
135135
});
136136

137+
test('名前にUnicode制御文字とスペースしか含まない場合はnullになる', async () => {
138+
const res = await api('i/update', {
139+
name: ' \u202e ',
140+
}, alice);
141+
assert.strictEqual(res.status, 200);
142+
assert.strictEqual(res.body.name, null);
143+
});
144+
137145
test('誕生日の設定を削除できる', async () => {
138146
await api('i/update', {
139147
birthday: '2000-09-07',

0 commit comments

Comments
 (0)