diff --git a/web/pgadmin/misc/file_manager/__init__.py b/web/pgadmin/misc/file_manager/__init__.py index 4a8e709..eb62c40 100644 --- a/web/pgadmin/misc/file_manager/__init__.py +++ b/web/pgadmin/misc/file_manager/__init__.py @@ -513,6 +513,8 @@ class Filemanager(object): """ path = unquote(path) + if hasattr(str, 'decode'): + path = unquote(path).encode('utf-8') if self.dir is None: self.dir = "" orig_path = "{0}{1}".format(self.dir, path) @@ -576,6 +578,8 @@ class Filemanager(object): # extract filename oldname = split_path(old)[-1] + if hasattr(str, 'decode'): + old = old.encode('utf-8') path = str(old) path = split_path(path)[0] # extract path @@ -584,6 +588,8 @@ class Filemanager(object): # newname = encode_urlpath(new) newname = new + if hasattr(str, 'decode'): + newname = new.encode('utf-8') newpath = path + newname # make system old path @@ -622,6 +628,7 @@ class Filemanager(object): } dir = self.dir if self.dir is not None else '' + path = path.encode('utf-8') if hasattr(str, 'decode') else path orig_path = "{0}{1}".format(dir, path) err_msg = '' @@ -660,11 +667,15 @@ class Filemanager(object): try: path = req.form.get('currentpath') orig_path = "{0}{1}".format(dir, path) - thefile = req.files['newfile'] - newName = '{0}{1}'.format(orig_path, thefile.filename) + + file_obj = req.files['newfile'] + file_name = file_obj.filename + if hasattr(str, 'decode'): + file_name = file_obj.filename.encode('utf-8') + newName = '{0}{1}'.format(orig_path, file_name) with open(newName, 'wb') as f: - f.write(thefile.read()) + f.write(file_obj.read()) code = 0 except Exception as e: err_msg = "Error: {0}".format(e.strerror) @@ -685,6 +696,9 @@ class Filemanager(object): err_msg = '' code = 1 name = unquote(name) + if hasattr(str, 'decode'): + name = unquote(name).encode('utf-8') + try: orig_path = "{0}{1}".format(dir, path) newName = '{0}{1}'.format(orig_path, name) @@ -735,10 +749,17 @@ class Filemanager(object): dir = self.dir if self.dir is not None else '' newName = name + if hasattr(str, 'decode'): + newName = name.encode('utf-8') + if dir != "": newPath = dir + '/' + path + newName + '/' + if hasattr(str, 'decode'): + newPath = dir + '/' + path + newName.decode('utf-8') + '/' else: newPath = path + newName + '/' + if hasattr(str, 'decode'): + newPath = path + newName.decode('utf-8') + '/' err_msg = '' code = 1 @@ -776,9 +797,10 @@ class Filemanager(object): } dir = self.dir if self.dir is not None else '' + path = path.encode('utf-8') if hasattr(str, 'decode') else path orig_path = "{0}{1}".format(dir, path) name = path.split('/')[-1] - content = open(orig_path, 'r') + content = open(orig_path, 'rb') resp = Response(content) resp.headers['Content-Disposition'] = 'attachment; filename=' + name return resp diff --git a/web/pgadmin/misc/file_manager/templates/file_manager/js/utility.js b/web/pgadmin/misc/file_manager/templates/file_manager/js/utility.js index f1a5ef4..cbf8f6e 100755 --- a/web/pgadmin/misc/file_manager/templates/file_manager/js/utility.js +++ b/web/pgadmin/misc/file_manager/templates/file_manager/js/utility.js @@ -78,47 +78,14 @@ var preg_replace = function(array_pattern, array_pattern_replace, str) { return new_str; }; -/* - * cleanString (), on the same model as server side (connector) - * cleanString - */ -var cleanString = function(str) { - var cleaned = ""; - var p_search = new Array( - "Š", "š", "Đ", "đ", "Ž", "ž", "Č", "č", "Ć", "ć", "À", - "Á", "Â", "Ã", "Ä", "Å", "Æ", "Ç", "È", "É", "Ê", "Ë", "Ì", "Í", "Î", "Ï", - "Ñ", "Ò", "Ó", "Ô", "Õ", "Ö", "Ő", "Ø", "Ù", "Ú", "Û", "Ü", "Ý", "Þ", "ß", - "à", "á", "â", "ã", "ä", "å", "æ", "ç", "è", "é", "ê", "ë", "ì", "í", - "î", "ï", "ð", "ñ", "ò", "ó", "ô", "õ", "ö", "ő", "ø", "ù", "ú", "û", "ü", - "ý", "ý", "þ", "ÿ", "Ŕ", "ŕ", " ", "'", "/" - ); - var p_replace = new Array( - "S", "s", "Dj", "dj", "Z", "z", "C", "c", "C", "c", "A", - "A", "A", "A", "A", "A", "A", "C", "E", "E", "E", "E", "I", "I", "I", "I", - "N", "O", "O", "O", "O", "O", "O", "O", "U", "U", "U", "U", "Y", "B", "Ss", - "a", "a", "a", "a", "a", "a", "a", "c", "e", "e", "e", "e", "i", "i", - "i", "i", "o", "n", "o", "o", "o", "o", "o", "o", "o", "u", "u", "u", "u", - "y", "y", "b", "y", "R", "r", "_", "_", "" - ); - - cleaned = preg_replace(p_search, p_replace, str); - cleaned = cleaned.replace(/[^_a-zA-Z0-9]/g, ""); - cleaned = cleaned.replace(/[_]+/g, "_"); - - return cleaned; -}; - -/* - * nameFormat (), separate filename from extension before calling cleanString() - * nameFormat - */ + //nameFormat (), separate filename from extension var nameFormat = function(input) { var filename = ''; if (input.lastIndexOf('.') != -1) { - filename = cleanString(input.substr(0, input.lastIndexOf('.'))); + filename = input.substr(0, input.lastIndexOf('.')); filename += '.' + input.split('.').pop(); } else { - filename = cleanString(input); + filename = input; } return filename; }; @@ -316,7 +283,7 @@ var setUploader = function(path) { var fname = value; if (fname != '') { - foldername = cleanString(fname); + foldername = fname; var d = new Date(); // to prevent IE cache issues $.getJSON(fileConnector + '?mode=addfolder&path=' + $('.currentpath').val() + '&name=' + foldername, function(resp) { var result = resp.data.result; @@ -366,7 +333,7 @@ var bindToolbar = function(data) { $('.fileinfo .delete_item button.btn_yes').unbind().on('click', function() { var path; if ($('.fileinfo').data('view') == 'grid') { - path = $('.fileinfo').find('#contents li.selected .clip span').attr('data-alt'); + path = decodeURI($('.fileinfo').find('#contents li.selected .clip span').attr('data-alt')); if (path.lastIndexOf('/') == path.length - 1) { data.Path = path; deleteItem(data); @@ -396,10 +363,10 @@ var bindToolbar = function(data) { var path; if ($('.fileinfo').data('view') == 'grid') { path = $('.fileinfo li.selected').find('.clip span').attr('data-alt'); - window.open(fileConnector + '?mode=download&path=' + encodeURIComponent(path), '_blank'); + window.open(fileConnector + '?mode=download&path=' + path, '_blank'); } else { path = $('.fileinfo').find('table#contents tbody tr.selected td:first-child').attr('title'); - window.open(fileConnector + '?mode=download&path=' + encodeURIComponent(path), '_blank'); + window.open(fileConnector + '?mode=download&path=' + path, '_blank'); } }); } diff --git a/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js b/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js index e2c7cad..7b36889 100644 --- a/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js +++ b/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js @@ -2286,7 +2286,7 @@ define( setTitle: function(title) { _.each(window.top.pgAdmin.Browser.docker.findPanels('frm_datagrid'), function(p) { if(p.isVisible()) { - p.title(title); + p.title(decodeURIComponent(title)); } }); },