diff --git a/django/test/client.py b/django/test/client.py index bac28f797b..bf9d85120e 100644 --- a/django/test/client.py +++ b/django/test/client.py @@ -1,5 +1,6 @@ import urllib import sys +import os from cStringIO import StringIO from django.conf import settings from django.contrib.auth import authenticate, login @@ -67,7 +68,7 @@ def encode_multipart(boundary, data): if isinstance(value, file): lines.extend([ '--' + boundary, - 'Content-Disposition: form-data; name="%s"; filename="%s"' % (to_str(key), to_str(value.name)), + 'Content-Disposition: form-data; name="%s"; filename="%s"' % (to_str(key), to_str(os.path.basename(value.name))), 'Content-Type: application/octet-stream', '', value.read() diff --git a/tests/regressiontests/test_client_regress/views.py b/tests/regressiontests/test_client_regress/views.py index f44757dc10..97379c1039 100644 --- a/tests/regressiontests/test_client_regress/views.py +++ b/tests/regressiontests/test_client_regress/views.py @@ -1,3 +1,5 @@ +import os + from django.contrib.auth.decorators import login_required from django.http import HttpResponse, HttpResponseRedirect, HttpResponseServerError @@ -13,6 +15,10 @@ def file_upload_view(request): form_data = request.POST.copy() form_data.update(request.FILES) if isinstance(form_data['file_field'], dict) and isinstance(form_data['name'], unicode): + # If a file is posted, the dummy client should only post the file name, + # not the full path. + if os.path.dirname(form_data['file_field']['filename']) != '': + return HttpResponseServerError() return HttpResponse('') else: return HttpResponseServerError()