Skip to content

Commit 6e98445

Browse files
committed
fix(guestName): limit length to 64 characters
This is the same limit we apply to authenticated user display names. The text app stores guest names in a 64 char database field. Note that this is counting characters - not bytes. So languages with multi-byte characters can still use 64 chars in name. Signed-off-by: Max <max@nextcloud.com>
1 parent 2ee987f commit 6e98445

4 files changed

Lines changed: 33 additions & 0 deletions

File tree

l10n/messages.pot

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ msgstr ""
100100
msgid "Name"
101101
msgstr ""
102102

103+
msgid "Names may be at most 64 characters long."
104+
msgstr ""
105+
103106
msgid "Names must not be empty."
104107
msgstr ""
105108

lib/components/PublicAuthPrompt.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ function onSubmit() {
196196
:placeholder="t('Enter your name')"
197197
:required="!cancellable"
198198
minlength="2"
199+
maxlength="64"
199200
name="name" />
200201
</NcDialog>
201202
</template>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
import { describe, expect, it, vi } from 'vitest'
7+
import { getGuestNameValidity } from './guestNameValidity.ts'
8+
9+
vi.mock('@nextcloud/files', () => ({
10+
validateFilename: vi.fn(),
11+
}))
12+
13+
describe('guestNameValidity', () => {
14+
it('rejects names that are too long', () => {
15+
const tooLong = 'This string is longer than 64 characters and therefore tooo long.'
16+
expect(tooLong.length).toBeGreaterThan(64)
17+
expect(getGuestNameValidity(tooLong)).toBe('Names may be at most 64 characters long.')
18+
})
19+
20+
it('Accepts long strings in 16 bit chars.', () => {
21+
const shortEnough = '人名用漢字 (Jinmeiyō-Kanji) used in names: 丑丞乃之也亀...'
22+
expect(shortEnough.length).toBeLessThan(64)
23+
expect(getGuestNameValidity(shortEnough)).toBe('')
24+
})
25+
})

lib/utils/guestNameValidity.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ export function getGuestNameValidity(name: string): string {
2020
return t('Names must not start with a dot.')
2121
}
2222

23+
if (name.length > 64) {
24+
return t('Names may be at most 64 characters long.')
25+
}
26+
2327
try {
2428
validateFilename(name)
2529
return ''

0 commit comments

Comments
 (0)