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

Catch ValueError when converting font encoding differences to characters #389

Merged
merged 4 commits into from
Mar 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## [Unreleased]

### Fixed

- Ignore ValueError when converting font encoding differences ([#389](https://github.com/pdfminer/pdfminer.six/pull/389))
- Grouping of text lines outside of parent container bounding box ([#386](https://github.com/pdfminer/pdfminer.six/pull/386))

## [20200124] - 2020-01-24
Expand Down
2 changes: 1 addition & 1 deletion pdfminer/encodingdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def get_encoding(cls, name, diff=None):
elif isinstance(x, PSLiteral):
try:
cid2unicode[cid] = name2unicode(x.name)
except KeyError as e:
except (KeyError, ValueError) as e:
log.debug(str(e))
cid += 1
return cid2unicode
12 changes: 11 additions & 1 deletion tests/test_encodingdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"""
from nose.tools import assert_raises

from pdfminer.encodingdb import name2unicode
from pdfminer.encodingdb import name2unicode, EncodingDB
from pdfminer.psparser import PSLiteral


def test_name2unicode_name_in_agl():
Expand Down Expand Up @@ -145,3 +146,12 @@ def test_name2unicode_pua_ogoneksmall():

def test_name2unicode_overflow_error():
assert_raises(KeyError, name2unicode, '226215240241240240240240')


def test_get_encoding_with_invalid_differences():
"""Invalid differences should be silently ignored

Regression test for https://github.com/pdfminer/pdfminer.six/issues/385
"""
invalid_differences = [PSLiteral('ubuntu'), PSLiteral('1234')]
EncodingDB.get_encoding('StandardEncoding', invalid_differences)