Merge pull request #44996 from nextcloud/fix/unify-access-to-forbidden-chars

fix(files): Use OCP\Util::getForbiddenFileNameChars instead of directaccess to system config
feat/upload-folders
Ferdinand Thiessen 3 weeks ago committed by GitHub
commit 316acc3cc3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -52,7 +52,6 @@ use OCP\AppFramework\Http\Response;
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;
@ -253,9 +252,8 @@ class ViewController extends Controller {
$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);

@ -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',
@ -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
},

@ -152,11 +152,6 @@ class ViewControllerTest extends TestCase {
'ownerDisplayName' => 'MyDisplayName',
]);
$this->config
->expects($this->any())
->method('getSystemValue')
->with('forbidden_chars', [])
->willReturn([]);
$this->config
->method('getUserValue')
->willReturnMap([

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save