From 6f6e2d0fb6dbdbc0d6d31e3f121defab47411b21 Mon Sep 17 00:00:00 2001 From: xevidos Date: Wed, 6 Mar 2019 16:36:08 -0500 Subject: [PATCH] Continued work on renaming files with invalid characters. --- components/filemanager/class.filemanager.php | 6 ++-- components/filemanager/init.js | 34 ++++++++++++++------ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/components/filemanager/class.filemanager.php b/components/filemanager/class.filemanager.php index 40ce782..4d2585f 100755 --- a/components/filemanager/class.filemanager.php +++ b/components/filemanager/class.filemanager.php @@ -774,12 +774,12 @@ class Filemanager extends Common { * trying to rename or delete it, allow the actual file name. */ + $invalid_characters = preg_match( '/[^A-Za-z0-9\-\._\/\ ]/', $path ); - - if( preg_match( '/[^A-Za-z0-9\-\._\/\ ]/', $path ) && ! ( $_GET['action'] == "modify" || $_GET['action'] == "delete" ) ) { + if( $invalid_characters && ! ( $_GET['action'] == "modify" || $_GET['action'] == "delete" ) ) { exit( '{"status":"error","message":"Error, the filename contains invalid characters, please either rename or delete it."}' ); - } elseif( preg_match( '/[^A-Za-z0-9\-\._\/\ ]/', $path ) && ( $_GET['action'] == "modify" || $_GET['action'] == "delete" ) ) { + } elseif( $invalid_characters && ( $_GET['action'] == "modify" || $_GET['action'] == "delete" ) ) { } else { $path = preg_replace( '/[^A-Za-z0-9\-\._\/\ ]/', '', $path ); diff --git a/components/filemanager/init.js b/components/filemanager/init.js index ae3828a..773b8e9 100755 --- a/components/filemanager/init.js +++ b/components/filemanager/init.js @@ -296,8 +296,13 @@ ////////////////////////////////////////////////////////////////// getType: function(path) { - return $('#file-manager a[data-path="' + path + '"]') - .attr('data-type'); + + if( path.match( /\\/g ) ) { + + path = path.replace( '\\', '\\\\' ); + } + + return $('#file-manager a[data-path="' + path + '"]').attr('data-type'); }, ////////////////////////////////////////////////////////////////// @@ -611,6 +616,7 @@ }); $('#modal-content form') .live('submit', function(e) { + let project = codiad.project.getCurrent(); e.preventDefault(); var shortName = $('#modal-content form input[name="object_name"]') .val(); @@ -631,7 +637,7 @@ codiad.filemanager.openFile(createPath, true); } - codiad.filemanager.rescan( path ); + codiad.filemanager.rescan( project ); /* Notify listeners. */ amplify.publish('filemanager.onCreate', {createPath: createPath, path: path, shortName: shortName, type: type}); @@ -660,6 +666,7 @@ } else if (path == this.clipboard) { codiad.message.error(i18n('Cannot Paste Directory Into Itself')); } else { + let project = codiad.project.getCurrent(); var shortName = _this.getShortName(_this.clipboard); if ($('#file-manager a[data-path="' + path + '/' + shortName + '"]') .length) { // Confirm overwrite? @@ -680,7 +687,7 @@ _this.processPasteNode(path,false); } - codiad.filemanager.rescan( path ); + codiad.filemanager.rescan( project ); } }, @@ -713,6 +720,7 @@ codiad.modal.load(250, this.dialog, { action: 'rename', path: path, short_name: shortName, type: type}); $('#modal-content form') .live('submit', function(e) { + let project = codiad.project.getCurrent(); e.preventDefault(); var newName = $('#modal-content form input[name="object_name"]') .val(); @@ -725,11 +733,19 @@ var newPath = temp.join('/') + '/' + newName; $.get(_this.controller, { action: 'modify', path: path, new_name: newName} , function(data) { var renameResponse = codiad.jsend.parse(data); + let renamedMessage = ""; if (renameResponse != 'error') { - codiad.message.success(type.charAt(0) - .toUpperCase() + type.slice(1) + ' Renamed'); + + if( type == undefined ) { + + renamedMessage = 'Successfully Renamed' + } else { + + renamedMessage = type.charAt(0).toUpperCase() + type.slice(1) + ' Renamed' + } + + codiad.message.success(renamedMessage); var node = $('#file-manager a[data-path="' + path + '"]'); - let parentPath = node.parent().parent().prev().attr('data-path'); // Change pathing and name for node node.attr('data-path', newPath) .html(newName); @@ -745,9 +761,9 @@ // Change any active files codiad.active.rename(path, newPath); codiad.modal.unload(); - codiad.filemanager.rescan( parentPath ); + codiad.filemanager.rescan( project ); /* Notify listeners. */ - amplify.publish('filemanager.onRename', {path: path, newPath: newPath, parentPath: parentPath }); + amplify.publish('filemanager.onRename', {path: path, newPath: newPath, project: project }); } }); });