diff --git a/CHANGELOG.md b/CHANGELOG.md index 919e06d..4a508b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Fix `.paint_path` logic for handling single line segments and extracting point-on-curve positions of BeziƩr path commands ([#530](https://github.com/pdfminer/pdfminer.six/pull/530)) - Raising `UnboundLocalError` when a bad `--output-type` is used ([#610](https://github.com/pdfminer/pdfminer.six/pull/610)) - `TypeError` when using `TagExtractor` with non-string or non-bytes tag values ([#610](https://github.com/pdfminer/pdfminer.six/pull/610)) +- Using `io.TextIOBase` as the file to write to ([#616](https://github.com/pdfminer/pdfminer.six/pull/616)) +- Parsing \r\n after the escape character in a literal string ([#616](https://github.com/pdfminer/pdfminer.six/pull/616)) ## Removed - Support for Python 3.4 and 3.5 ([#522](https://github.com/pdfminer/pdfminer.six/pull/522)) diff --git a/pdfminer/converter.py b/pdfminer/converter.py index de58f30..812f668 100644 --- a/pdfminer/converter.py +++ b/pdfminer/converter.py @@ -181,6 +181,8 @@ class PDFConverter(PDFLayoutAnalyzer): return True elif isinstance(outfp, io.StringIO): return False + elif isinstance(outfp, io.TextIOBase): + return False return True diff --git a/pdfminer/psparser.py b/pdfminer/psparser.py index 8c13ec4..10cf05a 100644 --- a/pdfminer/psparser.py +++ b/pdfminer/psparser.py @@ -444,16 +444,29 @@ class PSBaseParser: return j+1 def _parse_string_1(self, s, i): + """Parse literal strings + + PDF Reference 3.2.3 + """ c = s[i:i+1] if OCT_STRING.match(c) and len(self.oct) < 3: self.oct += c return i+1 - if self.oct: + + elif self.oct: self._curtoken += bytes((int(self.oct, 8),)) self._parse1 = self._parse_string return i - if c in ESC_STRING: + + elif c in ESC_STRING: self._curtoken += bytes((ESC_STRING[c],)) + + elif c == b'\r' and len(s) > i+1 and s[i+1:i+2] == b'\n': + # If current and next character is \r\n skip both because enters + # after a \ are ignored + i += 1 + + # default action self._parse1 = self._parse_string return i+1 diff --git a/tests/test_converter.py b/tests/test_converter.py index 99d1dc9..8781fa2 100644 --- a/tests/test_converter.py +++ b/tests/test_converter.py @@ -207,3 +207,6 @@ class TestBinaryDetector(): def test_non_file_like_object_defaults_to_binary(self): assert_true(PDFConverter._is_binary_stream(object())) + + def test_textiowrapper(self): + assert_false(PDFConverter._is_binary_stream(io.TextIOBase()))