handling special characters in gridftp urls
authorMaciej Tronowski <mtro@man.poznan.pl>
Mon, 20 Apr 2015 12:47:10 +0000 (14:47 +0200)
committerMaciej Tronowski <mtro@man.poznan.pl>
Mon, 20 Apr 2015 12:47:10 +0000 (14:47 +0200)
filex/forms.py
filex/ftp.py
pkgs/python-gridftp-1.3.3.tar.gz [deleted file]
pkgs/python-gridftp-1.3.4.tar.gz [new file with mode: 0644]
requirements.txt

index f73b175..26ca737 100644 (file)
@@ -4,6 +4,7 @@ import os
 from django import forms
 from django.core.exceptions import ValidationError
 from django.core.validators import RegexValidator
+from django.utils.http import urlquote
 
 from filex.models import Favorite
 
@@ -15,6 +16,10 @@ path_validator = RegexValidator(r'^/(?:[^/\0]+/?)*$', msg)
 name_validator = RegexValidator(r'^[^/\0]+$', msg)
 
 
+def clean_path(path):
+    return urlquote(os.path.normpath(path))
+
+
 class FavoriteForm(forms.ModelForm):
     class Meta:
         model = Favorite
@@ -30,7 +35,7 @@ class HostPathForm(HostForm):
     path = forms.CharField(label=u'Ścieżka', max_length=1024, validators=[path_validator], widget=forms.HiddenInput())
 
     def clean_path(self):
-        return os.path.normpath(self.cleaned_data['path'])
+        return clean_path(self.cleaned_data['path'])
 
 
 class HostPathNameForm(HostPathForm):
@@ -67,7 +72,7 @@ class HostItemsForm(HostForm):
                 e.message += ' - ' + name
                 errors.append(e)
             else:
-                cleaned.append(os.path.normpath(name))
+                cleaned.append(clean_path(name))
         if errors:
             raise ValidationError(errors)
 
@@ -85,17 +90,17 @@ class RenameForm(HostForm):
     dst = forms.CharField(label=u'Nowa nazwa', max_length=1024, validators=[path_validator])
 
     def clean_src(self):
-        return os.path.normpath(self.cleaned_data['src'])
+        return clean_path(self.cleaned_data['src'])
 
     def clean_dst(self):
-        return os.path.normpath(self.cleaned_data['dst'])
+        return clean_path(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 os.path.normpath(self.cleaned_data['dst'])
+        return clean_path(self.cleaned_data['dst'])
 
 
 class CompressForm(HostPathForm):
@@ -118,14 +123,14 @@ class CompressForm(HostPathForm):
                 e.message += ' - ' + name
                 errors.append(e)
             else:
-                cleaned.append(os.path.normpath(name))
+                cleaned.append(clean_path(name))
         if errors:
             raise ValidationError(errors)
 
         return cleaned
 
     def clean_archive(self):
-        return os.path.normpath(self.cleaned_data['archive'])
+        return clean_path(self.cleaned_data['archive'])
 
 
 class ArchiveForm(CompressForm):
index c9e90ff..29c4598 100644 (file)
@@ -162,10 +162,6 @@ class FTPOperation:
         return False
 
     def compress(self, server, path, files, archive):
-        for value in [path, archive] + files:
-            if '#' in value:
-                raise ValueError('Illegal character `#` in {}'.format(value))
-
         if self.match_ext(archive, '.tar.gz', '.tgz'):
             cmd, args = 'tar', ['cvzf', archive, '-C', path] + files
         elif self.match_ext(archive, '.tar.bz2', '.tbz'):
@@ -180,10 +176,6 @@ class FTPOperation:
         return self.get(server)
 
     def extract(self, server, archive, dst):
-        for value in [archive, dst]:
-            if '#' in value:
-                raise ValueError('Illegal character `#` in {}'.format(value))
-
         if self.match_ext(archive, '.tar.gz', '.tgz'):
             cmd, args = 'tar', ('xvzf', archive, '-C', dst)
         elif self.match_ext(archive, '.tar.bz2', '.tbz'):
diff --git a/pkgs/python-gridftp-1.3.3.tar.gz b/pkgs/python-gridftp-1.3.3.tar.gz
deleted file mode 100644 (file)
index cc34b44..0000000
Binary files a/pkgs/python-gridftp-1.3.3.tar.gz and /dev/null differ
diff --git a/pkgs/python-gridftp-1.3.4.tar.gz b/pkgs/python-gridftp-1.3.4.tar.gz
new file mode 100644 (file)
index 0000000..eff372e
Binary files /dev/null and b/pkgs/python-gridftp-1.3.4.tar.gz differ
index a68a0e7..29825a0 100644 (file)
@@ -3,6 +3,6 @@ django-grappelli
 django-bootstrap3
 pkgs/django-openid-auth-0.5.1.tar.gz
 pkgs/pyqcg-0.4.tar.gz
-pkgs/python-gridftp-1.3.3.tar.gz
+pkgs/python-gridftp-1.3.4.tar.gz
 python-openid
 pytz