Skip to content

Commit

Permalink
fix(files): Use OCP\Util::getForbiddenFileNameChars instead of direct…
Browse files Browse the repository at this point in the history
… access to system config

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux committed Apr 23, 2024
1 parent aa4e0bb commit 8572402
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
5 changes: 2 additions & 3 deletions apps/files/lib/Controller/ViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,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', implode('', $forbiddenCharacters));

$event = new LoadAdditionalScriptsEvent();
$this->eventDispatcher->dispatchTyped($event);
Expand Down
14 changes: 8 additions & 6 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 Expand Up @@ -201,7 +196,14 @@ public function testIndexWithRegularBrowser() {
],
]);

$this->assertEquals($expected, $this->viewController->index('MyDir', 'MyView'));
$config = \OCP\Server::get(IConfig::class);
$backupForbiddenChars = $config->getSystemValue('forbidden_chars', []);
try {
$config->setSystemValue('forbidden_chars', []);
$this->assertEquals($expected, $this->viewController->index('MyDir', 'MyView'));
} finally {
$config->setSystemValue('forbidden_chars', $backupForbiddenChars);
}
}

public function testShowFileRouteWithTrashedFile() {
Expand Down

0 comments on commit 8572402

Please sign in to comment.