Skip to content

Commit

Permalink
Merge pull request #44996 from nextcloud/fix/unify-access-to-forbidde…
Browse files Browse the repository at this point in the history
…n-chars

fix(files): Use OCP\Util::getForbiddenFileNameChars instead of directaccess to system config
  • Loading branch information
susnux authored Apr 29, 2024
2 parents 147426c + da04b8b commit 316acc3
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 19 deletions.
6 changes: 2 additions & 4 deletions apps/files/lib/Controller/ViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
use OCP\Collaboration\Resources\LoadAdditionalScriptsEvent as ResourcesLoadAdditionalScriptsEvent;
use OCP\Constants;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
Expand Down Expand Up @@ -253,9 +252,8 @@ public function index($dir = '', $view = '', $fileid = null, $fileNotFound = fal
$this->initialState->provideInitialState('filesSortingConfig', $filesSortingConfig);

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

$event = new LoadAdditionalScriptsEvent();
$this->eventDispatcher->dispatchTyped($event);
Expand Down
12 changes: 5 additions & 7 deletions apps/files/src/components/FileEntry/FileEntryName.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ import NcTextField from '@nextcloud/vue/dist/Components/NcTextField.js'
import { useRenamingStore } from '../../store/renaming.ts'
import logger from '../../logger.js'
const forbiddenCharacters = loadState('files', 'forbiddenCharacters', '') as string
const forbiddenCharacters = loadState<string[]>('files', 'forbiddenCharacters', [])
export default Vue.extend({
name: 'FileEntryName',
Expand Down Expand Up @@ -230,12 +230,10 @@ export default Vue.extend({
throw new Error(t('files', '{newName} already exists.', { newName: name }))
}
const toCheck = trimmedName.split('')
toCheck.forEach(char => {
if (forbiddenCharacters.indexOf(char) !== -1) {
throw new Error(this.t('files', '"{char}" is not allowed inside a file name.', { char }))
}
})
const char = forbiddenCharacters.find((char) => trimmedName.includes(char))
if (char) {
throw new Error(t('files', '"{char}" is not allowed inside a file name.', { char }))
}
return true
},
Expand Down
5 changes: 0 additions & 5 deletions apps/files/tests/Controller/ViewControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,6 @@ public function testIndexWithRegularBrowser() {
'ownerDisplayName' => 'MyDisplayName',
]);

$this->config
->expects($this->any())
->method('getSystemValue')
->with('forbidden_chars', [])
->willReturn([]);
$this->config
->method('getUserValue')
->willReturnMap([
Expand Down
4 changes: 2 additions & 2 deletions dist/files-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files-main.js.map

Large diffs are not rendered by default.

0 comments on commit 316acc3

Please sign in to comment.