aboutsummaryrefslogtreecommitdiffstats
path: root/core/src
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2020-02-19 12:42:54 +0100
committerJoas Schilling <coding@schilljs.com>2020-02-25 12:01:14 +0100
commite05362959f8d9abb5016914693dac01e564354df (patch)
tree81841c528300711198e820ba83684e6c995b0dbe /core/src
parent4cc017d52e975f2c4b527c8f848087c5e6136ccc (diff)
downloadnextcloud-server-e05362959f8d9abb5016914693dac01e564354df.tar.gz
nextcloud-server-e05362959f8d9abb5016914693dac01e564354df.zip
Copy isFileNameValid function, so the filepicker works without the files app
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'core/src')
-rw-r--r--core/src/OC/dialogs.js32
1 files changed, 30 insertions, 2 deletions
diff --git a/core/src/OC/dialogs.js b/core/src/OC/dialogs.js
index e9ffb5a6a15..cea857f6f2e 100644
--- a/core/src/OC/dialogs.js
+++ b/core/src/OC/dialogs.js
@@ -336,11 +336,39 @@ const Dialogs = {
$form.submit()
})
+
+ /**
+ * Checks whether the given file name is valid.
+ *
+ * @param name file name to check
+ * @return true if the file name is valid.
+ * @throws a string exception with an error message if
+ * the file name is not valid
+ *
+ * NOTE: This function is duplicated in the files app:
+ * https://github.com/nextcloud/server/blob/b9bc2417e7a8dc81feb0abe20359bedaf864f790/apps/files/js/files.js#L127-L148
+ */
+ var isFileNameValid = function (name) {
+ var trimmedName = name.trim();
+ if (trimmedName === '.' || trimmedName === '..')
+ {
+ throw t('files', '"{name}" is an invalid file name.', {name: name})
+ } else if (trimmedName.length === 0) {
+ throw t('files', 'File name cannot be empty.')
+ } else if (trimmedName.indexOf('/') !== -1) {
+ throw t('files', '"/" is not allowed inside a file name.')
+ } else if (!!(trimmedName.match(OC.config.blacklist_files_regex))) {
+ throw t('files', '"{name}" is not an allowed filetype', {name: name})
+ }
+
+ return true
+ }
+
var checkInput = function() {
var filename = $input.val()
try {
- if (!Files.isFileNameValid(filename)) {
- // Files.isFileNameValid(filename) throws an exception itself
+ if (!isFileNameValid(filename)) {
+ // isFileNameValid(filename) throws an exception itself
} else if (self.filelist.find(function(file) {
return file.name === this
}, filename)) {