Skip to content

Commit 316acc3

Browse files
authored
Merge pull request #44996 from nextcloud/fix/unify-access-to-forbidden-chars
fix(files): Use OCP\Util::getForbiddenFileNameChars instead of directaccess to system config
2 parents 147426c + da04b8b commit 316acc3

File tree

5 files changed

+10
-19
lines changed

5 files changed

+10
-19
lines changed

apps/files/lib/Controller/ViewController.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
use OCP\AppFramework\Http\TemplateResponse;
5353
use OCP\AppFramework\Services\IInitialState;
5454
use OCP\Collaboration\Resources\LoadAdditionalScriptsEvent as ResourcesLoadAdditionalScriptsEvent;
55-
use OCP\Constants;
5655
use OCP\EventDispatcher\IEventDispatcher;
5756
use OCP\Files\Folder;
5857
use OCP\Files\IRootFolder;
@@ -253,9 +252,8 @@ public function index($dir = '', $view = '', $fileid = null, $fileNotFound = fal
253252
$this->initialState->provideInitialState('filesSortingConfig', $filesSortingConfig);
254253

255254
// Forbidden file characters
256-
/** @var string[] */
257-
$forbiddenCharacters = $this->config->getSystemValue('forbidden_chars', []);
258-
$this->initialState->provideInitialState('forbiddenCharacters', Constants::FILENAME_INVALID_CHARS . implode('', $forbiddenCharacters));
255+
$forbiddenCharacters = \OCP\Util::getForbiddenFileNameChars();
256+
$this->initialState->provideInitialState('forbiddenCharacters', $forbiddenCharacters);
259257

260258
$event = new LoadAdditionalScriptsEvent();
261259
$this->eventDispatcher->dispatchTyped($event);

apps/files/src/components/FileEntry/FileEntryName.vue

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ import NcTextField from '@nextcloud/vue/dist/Components/NcTextField.js'
7070
import { useRenamingStore } from '../../store/renaming.ts'
7171
import logger from '../../logger.js'
7272
73-
const forbiddenCharacters = loadState('files', 'forbiddenCharacters', '') as string
73+
const forbiddenCharacters = loadState<string[]>('files', 'forbiddenCharacters', [])
7474
7575
export default Vue.extend({
7676
name: 'FileEntryName',
@@ -230,12 +230,10 @@ export default Vue.extend({
230230
throw new Error(t('files', '{newName} already exists.', { newName: name }))
231231
}
232232
233-
const toCheck = trimmedName.split('')
234-
toCheck.forEach(char => {
235-
if (forbiddenCharacters.indexOf(char) !== -1) {
236-
throw new Error(this.t('files', '"{char}" is not allowed inside a file name.', { char }))
237-
}
238-
})
233+
const char = forbiddenCharacters.find((char) => trimmedName.includes(char))
234+
if (char) {
235+
throw new Error(t('files', '"{char}" is not allowed inside a file name.', { char }))
236+
}
239237
240238
return true
241239
},

apps/files/tests/Controller/ViewControllerTest.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,6 @@ public function testIndexWithRegularBrowser() {
152152
'ownerDisplayName' => 'MyDisplayName',
153153
]);
154154

155-
$this->config
156-
->expects($this->any())
157-
->method('getSystemValue')
158-
->with('forbidden_chars', [])
159-
->willReturn([]);
160155
$this->config
161156
->method('getUserValue')
162157
->willReturnMap([

dist/files-main.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/files-main.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)