This commit is contained in:
Piotr Zalewa 2012-07-30 09:50:33 +02:00
Родитель 8add2a3a24
Коммит dd10b506c6
2 изменённых файлов: 18 добавлений и 3 удалений

Просмотреть файл

@ -355,6 +355,16 @@ class TestViews(TestCase):
eq_(resp.status_code, 404)
def test_attachment_with_utf_upload(self):
file_path = os.path.join(settings.ROOT,
'apps/jetpack/tests/jquery-1.6.4.min.js')
url = self.get_upload_url(self.revision.revision_number)
with open(file_path, 'r') as f:
response = self.client.post(url, { 'upload_attachment': f },
HTTP_X_FILE_NAME='jquery-1.6.4.min.js')
eq_(response.status_code, 200)
def test_attachment_rename(self):
revision = self.add_one()
old_uid = revision.attachments.all()[0].get_uid

Просмотреть файл

@ -549,16 +549,21 @@ def upload_attachment(request, id_number, type_id,
'You are not the author of this %s' % escape(
revision.package.get_type_name()))
file = request.FILES.get('upload_attachment')
f = request.FILES.get('upload_attachment')
filename = request.META.get('HTTP_X_FILE_NAME')
if not file:
if not f:
log_msg = 'Path not found: %s, package: %s.' % (
filename, id_number)
log.error(log_msg)
return HttpResponseServerError('Path not found.')
content = file.read()
content = f.read()
# try to force UTF-8 code, on error continue with original data
try:
content = unicode(content, 'utf-8')
except:
pass
try:
attachment = revision.attachment_create_by_filename(