Skip to content

Commit 264262f

Browse files
committed
chore!: remove deprecated fallbacks for Nextcloud 29 and below
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent 74c7115 commit 264262f

5 files changed

Lines changed: 23 additions & 23 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66

77
All notable changes to this project will be documented in this file.
88

9+
## 4.0.0 (UNRELEASED)
10+
### 📝 Notes
11+
* The support for Nextcloud versions below 30 has been removed,
12+
this means some functions like filename validation will now only
13+
work with the capabilities provided by Nextcloud 30 or newer.
14+
915
## 4.0.0-beta.1 - 2025-11-27
1016
### 🐛 Fixed bugs
1117
* fix: actions type exports by @skjnldsv in https://github.com/nextcloud-libraries/nextcloud-files/pull/1381

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ This library provides three kinds of utils:
1313
2. Geneal purpose function related to files or folders, like filename validation.
1414
3. Functions and classes to interact with the Nextcloud **files** app, like registering a new view or a file action.
1515

16+
## Compatibility
17+
18+
| `@nextcloud/files` version | Supported | Nextcloud version |
19+
|----------------------------|-----------|-------------------|
20+
| 4.x || 30+ |
21+
| 3.x || 26+ |
22+
| 2.x || 23-25 |
23+
| 1.x || 20-22 |
24+
1625
## Usage examples
1726

1827
### Files app

__tests__/utils/filename-validation.spec.ts

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,6 @@ describe('validateFilename', () => {
4949
expect(() => validateFilename('.htaccess')).toThrowError(InvalidFilenameError)
5050
})
5151

52-
it('has fallback invalid extension', async () => {
53-
expect(() => validateFilename('file.txt.part')).toThrowError(InvalidFilenameError)
54-
expect(() => validateFilename('file.txt.filepart')).toThrowError(InvalidFilenameError)
55-
})
56-
57-
// Nextcloud 29
58-
it('fallback fetching forbidden characters from oc config', async () => {
59-
window._oc_config = { forbidden_filenames_characters: ['=', '?'] }
60-
expect(() => validateFilename('foo.bar')).not.toThrow()
61-
expect(() => validateFilename('foo=bar')).toThrowError(InvalidFilenameError)
62-
expect(() => validateFilename('foo?bar')).toThrowError(InvalidFilenameError)
63-
})
64-
6552
// Nextcloud 30+
6653
it('fetches forbidden characters from capabilities', async () => {
6754
nextcloudCapabilities.getCapabilities.mockImplementation(() => ({ files: { forbidden_filename_characters: ['=', '?'] } }))
@@ -136,14 +123,16 @@ describe('validateFilename', () => {
136123
})
137124

138125
it('sets error properties correctly on invalid extension', async () => {
126+
nextcloudCapabilities.getCapabilities.mockImplementation(() => ({ files: { forbidden_filename_extensions: ['.txt'] } }))
127+
139128
try {
140-
validateFilename('file.part')
129+
validateFilename('file.txt')
141130
expect(true, 'should not be reached').toBeFalsy()
142131
} catch (error) {
143132
expect(error).toBeInstanceOf(InvalidFilenameError)
144133
expect((error as InvalidFilenameError).reason).toBe(InvalidFilenameErrorReason.Extension)
145-
expect((error as InvalidFilenameError).segment).toBe('.part')
146-
expect((error as InvalidFilenameError).filename).toBe('file.part')
134+
expect((error as InvalidFilenameError).segment).toBe('.txt')
135+
expect((error as InvalidFilenameError).filename).toBe('file.txt')
147136
}
148137
})
149138

lib/utils/filename-validation.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export function validateFilename(filename: string): void {
7878

7979
// Handle forbidden characters
8080
// This needs to be done first as the other checks are case insensitive!
81-
const forbiddenCharacters = capabilities.forbidden_filename_characters ?? window._oc_config?.forbidden_filenames_characters ?? ['/', '\\']
81+
const forbiddenCharacters = capabilities.forbidden_filename_characters ?? ['/', '\\']
8282
for (const character of forbiddenCharacters) {
8383
if (filename.includes(character)) {
8484
throw new InvalidFilenameError({ segment: character, reason: InvalidFilenameErrorReason.Character, filename })
@@ -102,9 +102,7 @@ export function validateFilename(filename: string): void {
102102
throw new InvalidFilenameError({ filename, segment: basename, reason: InvalidFilenameErrorReason.ReservedName })
103103
}
104104

105-
// The legacy 'blacklist_files_regex' was hardcoded to the extension '.part' and '.filepart'
106-
// So if the new (Nextcloud 30) capability is not awailable then we fallback to that
107-
const forbiddenFilenameExtensions = capabilities.forbidden_filename_extensions ?? ['.part', '.filepart']
105+
const forbiddenFilenameExtensions = capabilities.forbidden_filename_extensions ?? []
108106
for (const extension of forbiddenFilenameExtensions) {
109107
if (filename.length > extension.length && filename.endsWith(extension)) {
110108
throw new InvalidFilenameError({ segment: extension, reason: InvalidFilenameErrorReason.Extension, filename })
@@ -114,7 +112,7 @@ export function validateFilename(filename: string): void {
114112

115113
/**
116114
* Check the validity of a filename
117-
* This is a convinient wrapper for `checkFilenameValidity` to only return a boolean for the valid
115+
* This is a convenient wrapper for `checkFilenameValidity` to only return a boolean for the valid
118116
* @param filename Filename to check validity
119117
*/
120118
export function isFilenameValid(filename: string): boolean {

lib/window.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ declare global {
3333

3434
_oc_config?: {
3535
forbidden_filenames_characters: string[]
36-
/** @deprecated */
37-
blacklist_files_regex?: string
3836
}
3937
}
4038
}

0 commit comments

Comments
 (0)