fix in handling file name with special characters
authorMaciej Tronowski <mtro@man.poznan.pl>
Wed, 2 Sep 2015 13:18:11 +0000 (15:18 +0200)
committerDawid Jagieła <lightnir@gmail.com>
Sat, 12 Sep 2015 10:08:27 +0000 (12:08 +0200)
filex/forms.py
filex/views.py

index 4f7c8dd..e4d0c9e 100644 (file)
@@ -3,16 +3,11 @@ import os
 
 from django import forms
 from django.core.exceptions import ValidationError
-from django.utils.http import urlquote
 
 from filex.models import Favorite
 from filex.utils import host_validator, path_validator, name_validator
 
 
-def clean_path(path):
-    return urlquote(os.path.normpath(path), safe='/~')
-
-
 class FavoriteForm(forms.ModelForm):
     class Meta:
         model = Favorite
@@ -31,14 +26,14 @@ class HostPathForm(HostForm):
     path = forms.CharField(label=u'Ścieżka', max_length=1024, validators=[path_validator], widget=forms.HiddenInput())
 
     def clean_path(self):
-        return clean_path(self.cleaned_data['path'])
+        return os.path.normpath(self.cleaned_data['path'])
 
 
 class HostPathNameForm(HostPathForm):
     name = forms.CharField(label=u'Nazwa', max_length=256, validators=[name_validator])
 
     def clean_name(self):
-        return clean_path(self.cleaned_data['name'])
+        return os.path.normpath(self.cleaned_data['name'])
 
 
 class HostItemsForm(HostForm):
@@ -71,7 +66,7 @@ class HostItemsForm(HostForm):
                 e.message += ' - ' + name
                 errors.append(e)
             else:
-                cleaned.append(clean_path(name))
+                cleaned.append(os.path.normpath(name))
         if errors:
             raise ValidationError(errors)
 
@@ -89,17 +84,17 @@ class RenameForm(HostForm):
     dst = forms.CharField(label=u'Nowa nazwa', max_length=1024, validators=[path_validator])
 
     def clean_src(self):
-        return clean_path(self.cleaned_data['src'])
+        return os.path.normpath(self.cleaned_data['src'])
 
     def clean_dst(self):
-        return clean_path(self.cleaned_data['dst'])
+        return os.path.normpath(self.cleaned_data['dst'])
 
 
 class ExtractForm(HostPathForm):
     dst = forms.CharField(label=u'Katalog docelowy', max_length=1024, validators=[path_validator])
 
     def clean_dst(self):
-        return clean_path(self.cleaned_data['dst'])
+        return os.path.normpath(self.cleaned_data['dst'])
 
 
 class CompressForm(HostPathForm):
@@ -122,14 +117,14 @@ class CompressForm(HostPathForm):
                 e.message += ' - ' + name
                 errors.append(e)
             else:
-                cleaned.append(clean_path(name))
+                cleaned.append(os.path.normpath(name))
         if errors:
             raise ValidationError(errors)
 
         return cleaned
 
     def clean_archive(self):
-        return clean_path(self.cleaned_data['archive'])
+        return os.path.normpath(self.cleaned_data['archive'])
 
 
 class ArchiveForm(CompressForm):
index 1904d4f..ada8b7b 100644 (file)
@@ -9,6 +9,7 @@ from django.http import JsonResponse, StreamingHttpResponse
 from django.shortcuts import get_object_or_404, render
 from django.template.defaultfilters import filesizeformat
 from django.utils.formats import date_format
+from django.utils.http import urlquote
 from django.views.decorators.http import require_POST
 from django.views.generic import View
 
@@ -112,7 +113,7 @@ class DeleteView(FTPView):
 
         for path in params['dirs']:
             try:
-                ftp.rmdir(url + path)
+                ftp.rmdir(url + urlquote(path))
             except FTPError as e:
                 fail[path] = e.message
             else:
@@ -120,7 +121,7 @@ class DeleteView(FTPView):
 
         for path in params['files']:
             try:
-                ftp.delete(url + path)
+                ftp.delete(url + urlquote(path))
             except FTPError as e:
                 fail[path] = e.message
             else:
@@ -178,7 +179,8 @@ class ExtractView(FTPView):
 
 
 def make_url(params, *parts):
-    return 'gsiftp://{}/{}'.format(params['host'], os.path.join(*[params[part] for part in parts]) if parts else '')
+    return 'gsiftp://{}/{}'.format(params['host'],
+                                   urlquote(os.path.join(*[params[part] for part in parts]), safe='/~') if parts else '')
 
 
 @require_POST