summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--django/core/files/base.py2
-rw-r--r--tests/files/tests.py8
2 files changed, 9 insertions, 1 deletions
diff --git a/django/core/files/base.py b/django/core/files/base.py
index b1325291c6..641ff924c6 100644
--- a/django/core/files/base.py
+++ b/django/core/files/base.py
@@ -104,7 +104,7 @@ class File(FileProxyMixin):
# If this is the end of a line, yield
# otherwise, wait for the next round
- if line[-1] in ('\n', '\r'):
+ if line[-1:] in (b'\n', b'\r'):
yield line
else:
buffer_ = line
diff --git a/tests/files/tests.py b/tests/files/tests.py
index f562b5748d..b9f8b5228a 100644
--- a/tests/files/tests.py
+++ b/tests/files/tests.py
@@ -64,6 +64,14 @@ class FileTests(unittest.TestCase):
self.assertFalse(hasattr(file, 'mode'))
gzip.GzipFile(fileobj=file)
+ def test_file_iteration(self):
+ """
+ File objects should yield lines when iterated over.
+ Refs #22107.
+ """
+ file = File(BytesIO(b'one\ntwo\nthree'))
+ self.assertEqual(list(file), [b'one\n', b'two\n', b'three'])
+
class NoNameFileTestCase(unittest.TestCase):
"""