summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Fedoseev <fedoseev.sergey@gmail.com>2014-11-21 19:26:46 +0500
committerTim Graham <timograham@gmail.com>2014-11-24 15:54:57 -0500
commit1e9ac504e46cae277398ee21038a08fffaafd060 (patch)
tree824d3d4e9f401bf53571ac69374f864a9c325a01
parentebb927c4c997d4c8d9a55ec78cd2476a13bd1782 (diff)
Fixed #23888 -- Fixed crash in File.__repr__() when name contains unicode.
-rw-r--r--django/core/files/base.py7
-rw-r--r--docs/releases/1.7.2.txt3
-rw-r--r--tests/files/tests.py11
3 files changed, 12 insertions, 9 deletions
diff --git a/django/core/files/base.py b/django/core/files/base.py
index c1c9199cb5..0c6109f1b4 100644
--- a/django/core/files/base.py
+++ b/django/core/files/base.py
@@ -3,10 +3,11 @@ from __future__ import unicode_literals
import os
from io import BytesIO, StringIO, UnsupportedOperation
-from django.utils.encoding import smart_text
from django.core.files.utils import FileProxyMixin
from django.utils import six
-from django.utils.encoding import force_bytes, python_2_unicode_compatible
+from django.utils.encoding import (
+ force_bytes, force_str, python_2_unicode_compatible, smart_text,
+)
@python_2_unicode_compatible
@@ -25,7 +26,7 @@ class File(FileProxyMixin):
return smart_text(self.name or '')
def __repr__(self):
- return "<%s: %s>" % (self.__class__.__name__, self or "None")
+ return force_str("<%s: %s>" % (self.__class__.__name__, self or "None"))
def __bool__(self):
return bool(self.name)
diff --git a/docs/releases/1.7.2.txt b/docs/releases/1.7.2.txt
index c9f69fe856..62419be63e 100644
--- a/docs/releases/1.7.2.txt
+++ b/docs/releases/1.7.2.txt
@@ -77,3 +77,6 @@ Bugfixes
* Fixed a crash in migrations when deleting a field that is part of a
``index/unique_together`` constraint (:ticket:`23794`).
+
+* Fixed ``django.core.files.File.__repr__()`` when the file's ``name`` contains
+ Unicode characters (:ticket:`23888`).
diff --git a/tests/files/tests.py b/tests/files/tests.py
index f2f1df3626..e16ebd0729 100644
--- a/tests/files/tests.py
+++ b/tests/files/tests.py
@@ -26,13 +26,12 @@ else:
class FileTests(unittest.TestCase):
def test_unicode_uploadedfile_name(self):
- """
- Regression test for #8156: files with unicode names I can't quite figure
- out the encoding situation between doctest and this file, but the actual
- repr doesn't matter; it just shouldn't return a unicode object.
- """
uf = UploadedFile(name='¿Cómo?', content_type='text')
- self.assertEqual(type(uf.__repr__()), str)
+ self.assertIs(type(repr(uf)), str)
+
+ def test_unicode_file_name(self):
+ f = File(None, 'djángö')
+ self.assertIs(type(repr(f)), str)
def test_context_manager(self):
orig_file = tempfile.TemporaryFile()