diff --git a/apps/jetpack/models.py b/apps/jetpack/models.py index af8254da..a1702326 100644 --- a/apps/jetpack/models.py +++ b/apps/jetpack/models.py @@ -83,6 +83,9 @@ TYPE_CHOICES = ( ) +FILENAME_RE = r'[^a-zA-Z0-9=!@#\$%\^&\(\)\+\-_\/\.]+' + + class PackageRevision(BaseModel): """ contains data which may be changed and rolled back @@ -1934,7 +1937,7 @@ class Module(BaseModel): self.filename = self.filename[:first_period] # remove illegal characters from filename - self.filename = re.sub('[^a-zA-Z0-9=!@#\$%\^&\(\)\+\-_\/\.]+', '-', + self.filename = re.sub(FILENAME_RE, '-', self.filename) self.filename = re.sub('\/{2,}', '/', self.filename) self.filename = re.sub('^\/', '', self.filename) @@ -2095,7 +2098,7 @@ class Attachment(BaseModel): return self def clean(self): - self.filename = pathify(self.filename) + self.filename = re.sub(FILENAME_RE, '-', self.filename) if self.ext: self.ext = alphanum(self.ext) diff --git a/apps/jetpack/tests/attachment_test.py b/apps/jetpack/tests/attachment_test.py index db8e7ef6..816c3c19 100644 --- a/apps/jetpack/tests/attachment_test.py +++ b/apps/jetpack/tests/attachment_test.py @@ -408,12 +408,12 @@ class TestViews(TestCase): revision = self.add_one(filename='^you*()"[]"are-_crazy') att = revision.attachments.all()[0] - eq_(att.filename, '-you-are-_crazy') + eq_(att.filename, '^you-()-are-_crazy') revision.attachment_remove(att) revision = self.add_one(filename='">test') att = revision.attachments.all()[0] - eq_(att.filename, '-a-href-test') + eq_(att.filename, '-a-href=-test') revision.attachment_remove(att) revision = self.add_one(filename='template.html.js') @@ -433,6 +433,11 @@ class TestViews(TestCase): eq_(att.ext, 'ahref') revision.attachment_remove(att) + revision = self.add_one(filename='data+test.js') + att = revision.attachments.all()[0] + eq_(att.filename, 'data+test') + revision.attachment_remove(att) + def get_revision_from_response(self, response): return self.package.revisions.filter( revision_number=response['revision_number']).get() diff --git a/media/jetpack/js/Sidebar.js b/media/jetpack/js/Sidebar.js index b002ab4b..e27f80b8 100644 --- a/media/jetpack/js/Sidebar.js +++ b/media/jetpack/js/Sidebar.js @@ -453,7 +453,7 @@ var Sidebar = new Class({ // remove janky characters from filenames // (from promptAttachment) - filename = filename.replace(/[^a-zA-Z0-9\-_\/\.]+/g, '-'); + filename = filename.replace(/[^a-zA-Z0-9=!@#\$%\^&\(\)\+\-_\/\.]+/g, '-'); filename = filename.replace(/\/{2,}/g, '/'); if (filename[filename.length-1] == '/') {