Skip to content

Commit 2ebf88a

Browse files
Merge pull request #19539 from nextcloud/bugfix/noid/allow-to-create-directories-when-they-are-selectable
Allow to create directories when they are selectable
2 parents e620673 + e053629 commit 2ebf88a

8 files changed

Lines changed: 44 additions & 14 deletions

File tree

apps/files/js/files.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@
130130
* @return true if the file name is valid.
131131
* Throws a string exception with an error message if
132132
* the file name is not valid
133+
*
134+
* NOTE: This function is duplicated in the filepicker inside core/src/OC/dialogs.js
133135
*/
134136
isFileNameValid: function (name) {
135137
var trimmedName = name.trim();

core/js/dist/login.js

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

core/js/dist/login.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.

core/js/dist/main.js

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

core/js/dist/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.

core/js/dist/maintenance.js

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

core/js/dist/maintenance.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.

core/src/OC/dialogs.js

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ const Dialogs = {
299299
}
300300

301301
var newButton = self.$filePicker.find('.actions.creatable .button-add')
302-
if (type === self.FILEPICKER_TYPE_CHOOSE) {
302+
if (type === self.FILEPICKER_TYPE_CHOOSE && !options.allowDirectoryChooser) {
303303
newButton.hide()
304304
}
305305
newButton.on('focus', function() {
@@ -318,7 +318,7 @@ const Dialogs = {
318318
self.$filePicker.ocdialog('setEnterCallback', function() {
319319
event.stopImmediatePropagation()
320320
event.preventDefault()
321-
self.$form.submit()
321+
self.$filePicker.submit()
322322
})
323323
var newName = $input.val()
324324
var lastPos = newName.lastIndexOf('.')
@@ -336,11 +336,39 @@ const Dialogs = {
336336
$form.submit()
337337
})
338338

339+
340+
/**
341+
* Checks whether the given file name is valid.
342+
*
343+
* @param name file name to check
344+
* @return true if the file name is valid.
345+
* @throws a string exception with an error message if
346+
* the file name is not valid
347+
*
348+
* NOTE: This function is duplicated in the files app:
349+
* https://github.com/nextcloud/server/blob/b9bc2417e7a8dc81feb0abe20359bedaf864f790/apps/files/js/files.js#L127-L148
350+
*/
351+
var isFileNameValid = function (name) {
352+
var trimmedName = name.trim();
353+
if (trimmedName === '.' || trimmedName === '..')
354+
{
355+
throw t('files', '"{name}" is an invalid file name.', {name: name})
356+
} else if (trimmedName.length === 0) {
357+
throw t('files', 'File name cannot be empty.')
358+
} else if (trimmedName.indexOf('/') !== -1) {
359+
throw t('files', '"/" is not allowed inside a file name.')
360+
} else if (!!(trimmedName.match(OC.config.blacklist_files_regex))) {
361+
throw t('files', '"{name}" is not an allowed filetype', {name: name})
362+
}
363+
364+
return true
365+
}
366+
339367
var checkInput = function() {
340368
var filename = $input.val()
341369
try {
342-
if (!Files.isFileNameValid(filename)) {
343-
// Files.isFileNameValid(filename) throws an exception itself
370+
if (!isFileNameValid(filename)) {
371+
// isFileNameValid(filename) throws an exception itself
344372
} else if (self.filelist.find(function(file) {
345373
return file.name === this
346374
}, filename)) {

0 commit comments

Comments
 (0)