From 37f3631ad8c37da61487136b914cd8f73cf7134c Mon Sep 17 00:00:00 2001 From: zhengxie Date: Mon, 25 Feb 2013 16:39:20 +0800 Subject: [PATCH] Fixed bug in quoting/unquoting string --- api2/views.py | 11 ++++++----- views.py | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/api2/views.py b/api2/views.py index 59e39c6598..5c92dc477e 100644 --- a/api2/views.py +++ b/api2/views.py @@ -527,8 +527,7 @@ class StarredFileView(APIView): def post(self, request, format=None): # add starred file repo_id = request.POST.get('repo_id', '') - path = unquote(request.POST.get('p', '')) - + path = unquote(request.POST.get('p', '').encode('utf-8')) if not (repo_id and path): return api_error(status.HTTP_400_BAD_REQUEST, 'Repo_id or path is missing.') @@ -630,6 +629,7 @@ class FileView(APIView): 'The new name is the same to the old') newname = check_filename_with_rename(repo_id, parent_dir, newname) + newname_utf8 = newname.encode('utf-8') try: seafserv_threaded_rpc.rename_file (repo_id, parent_dir_utf8, oldname_utf8, newname, @@ -643,7 +643,7 @@ class FileView(APIView): else: resp = Response('success', status=status.HTTP_301_MOVED_PERMANENTLY) uri = reverse('FileView', args=[repo_id], request=request) - resp['Location'] = uri + '?p=' + quote(parent_dir_utf8) + quote(newname) + resp['Location'] = uri + '?p=' + quote(parent_dir_utf8) + quote(newname_utf8) return resp elif operation.lower() == 'move': @@ -741,7 +741,7 @@ class FileSharedLinkView(APIView): def put(self, request, repo_id, format=None): # generate file shared link - path = unquote(request.DATA.get('p', '')) + path = unquote(request.DATA.get('p', '').encode('utf-8')) if not path: return api_error(status.HTTP_400_BAD_REQUEST, 'Path is missing.') @@ -838,6 +838,7 @@ class DirView(APIView): operation = request.POST.get('operation', '') if operation.lower() == 'mkdir': parent_dir = os.path.dirname(path) + parent_dir_utf8 = parent_dir.encode('utf-8') new_dir_name = os.path.basename(path) new_dir_name = check_filename_with_rename(repo_id, parent_dir, new_dir_name) @@ -856,7 +857,7 @@ class DirView(APIView): else: resp = Response('success', status=status.HTTP_201_CREATED) uri = reverse('DirView', args=[repo_id], request=request) - resp['Location'] = uri + '?p=' + quote(parent_dir) + \ + resp['Location'] = uri + '?p=' + quote(parent_dir_utf8) + \ quote(new_dir_name_utf8) return resp # elif operation.lower() == 'rename': diff --git a/views.py b/views.py index 2c0d80bb79..9fc7ce74e8 100644 --- a/views.py +++ b/views.py @@ -1772,7 +1772,7 @@ def get_repo_download_url(request, repo_id): return '', _(u"Invalid server setting") ccnet_applet_root = get_ccnetapplet_root() - email = urllib2.quote(request.user.username) + email = urllib2.quote(request.user.username.encode('utf-8')) url = ccnet_applet_root + "/repo/download/"