Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: _is_binary_stream should recognize TextIOWrapper as non-binary, escaped \r\n should be removed #616

Merged
merged 21 commits into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 2 additions & 0 deletions pdfminer/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ def _is_binary_stream(outfp):
return True
elif isinstance(outfp, io.StringIO):
return False
elif isinstance(outfp, io.TextIOBase):
return False

return True

Expand Down
17 changes: 15 additions & 2 deletions pdfminer/psparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,16 +444,29 @@ def _parse_string(self, s, i):
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

Expand Down
3 changes: 3 additions & 0 deletions tests/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,6 @@ def test_binary_tmpfile(self):

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()))