summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/test/test_io.py10
-rw-r--r--Misc/NEWS.d/next/Library/2018-10-29-23-09-24.bpo-35062.dQS1ng.rst2
-rw-r--r--Modules/_io/textio.c2
3 files changed, 13 insertions, 1 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
index f306917..f29c16c 100644
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -3547,6 +3547,16 @@ class IncrementalNewlineDecoderTest(unittest.TestCase):
dec = self.IncrementalNewlineDecoder(None, translate=True)
_check(dec)
+ def test_translate(self):
+ # issue 35062
+ for translate in (-2, -1, 1, 2):
+ decoder = codecs.getincrementaldecoder("utf-8")()
+ decoder = self.IncrementalNewlineDecoder(decoder, translate)
+ self.check_newline_decoding_utf8(decoder)
+ decoder = codecs.getincrementaldecoder("utf-8")()
+ decoder = self.IncrementalNewlineDecoder(decoder, translate=0)
+ self.assertEqual(decoder.decode(b"\r\r\n"), "\r\r\n")
+
class CIncrementalNewlineDecoderTest(IncrementalNewlineDecoderTest):
pass
diff --git a/Misc/NEWS.d/next/Library/2018-10-29-23-09-24.bpo-35062.dQS1ng.rst b/Misc/NEWS.d/next/Library/2018-10-29-23-09-24.bpo-35062.dQS1ng.rst
new file mode 100644
index 0000000..b77ed86
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2018-10-29-23-09-24.bpo-35062.dQS1ng.rst
@@ -0,0 +1,2 @@
+Fix incorrect parsing of :class:`_io.IncrementalNewlineDecoder`'s
+*translate* argument.
diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c
index d582d3f..ebc3c04 100644
--- a/Modules/_io/textio.c
+++ b/Modules/_io/textio.c
@@ -268,7 +268,7 @@ _io_IncrementalNewlineDecoder___init___impl(nldecoder_object *self,
self->errors = errors;
}
- self->translate = translate;
+ self->translate = translate ? 1 : 0;
self->seennl = 0;
self->pendingcr = 0;