Skip to content

Commit

Permalink
Fix issue jsvine#33 by checking decode_text arg type
Browse files Browse the repository at this point in the history
  • Loading branch information
jsvine committed May 11, 2017
1 parent 8465877 commit c9e45ce
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pdfplumber/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def decode_text(s):
Decodes a PDFDocEncoding string to Unicode.
Adds py3 compatability to pdfminer's version.
"""
if s.startswith(b'\xfe\xff'):
if type(s) == bytes and s.startswith(b'\xfe\xff'):
return six.text_type(s[2:], 'utf-16be', 'ignore')
else:
ords = (ord(c) if type(c) == str else c for c in s)
Expand Down
Binary file added tests/pdfs/issue-33-lorem-ipsum.pdf
Binary file not shown.
11 changes: 9 additions & 2 deletions tests/test-issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,17 @@ def test_issue_14(self):
pdf = pdfplumber.from_path(
os.path.join(HERE, "pdfs/cupertino_usd_4-6-16.pdf")
)
len(pdf.objects)
assert len(pdf.objects)

def test_issue_21(self):
pdf = pdfplumber.from_path(
os.path.join(HERE, "pdfs/150109DSP-Milw-505-90D.pdf")
)
len(pdf.objects)
assert len(pdf.objects)

def test_issue_33(self):
pdf = pdfplumber.from_path(
os.path.join(HERE, "pdfs/issue-33-lorem-ipsum.pdf")
)
assert len(pdf.metadata.keys())

0 comments on commit c9e45ce

Please sign in to comment.