Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions l10n/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ msgstr ""
msgid "Name"
msgstr ""

msgid "Names may be at most 64 characters long."
msgstr ""

msgid "Names must not be empty."
msgstr ""

Expand Down
1 change: 1 addition & 0 deletions lib/components/PublicAuthPrompt.vue
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ function onSubmit() {
:placeholder="t('Enter your name')"
:required="!cancellable"
minlength="2"
maxlength="64"
name="name" />
</NcDialog>
</template>
Expand Down
25 changes: 25 additions & 0 deletions lib/utils/guestNameValidity.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { describe, expect, it, vi } from 'vitest'
import { getGuestNameValidity } from './guestNameValidity.ts'

vi.mock('@nextcloud/files', () => ({
validateFilename: vi.fn(),
}))

describe('guestNameValidity', () => {
it('rejects names that are too long', () => {
const tooLong = 'This string is longer than 64 characters and therefore tooo long.'
expect(tooLong.length).toBeGreaterThan(64)
expect(getGuestNameValidity(tooLong)).toBe('Names may be at most 64 characters long.')
})

it('Accepts long strings in 16 bit chars.', () => {
const shortEnough = '人名用漢字 (Jinmeiyō-Kanji) used in names: 丑丞乃之也亀...'
expect(shortEnough.length).toBeLessThan(64)
expect(getGuestNameValidity(shortEnough)).toBe('')
})
})
4 changes: 4 additions & 0 deletions lib/utils/guestNameValidity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ export function getGuestNameValidity(name: string): string {
return t('Names must not start with a dot.')
}

if (name.length > 64) {
return t('Names may be at most 64 characters long.')
}

try {
validateFilename(name)
return ''
Expand Down