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: Use the correct name StandardEncoding for the predefined cmap #3156

Merged
merged 3 commits into from
Feb 26, 2025
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
4 changes: 2 additions & 2 deletions pypdf/_cmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@
f"Advanced encoding {encoding} not implemented yet",
__name__,
)
encoding = charset_encoding["/StandardCoding"].copy()
encoding = charset_encoding["/StandardEncoding"].copy()

Check warning on line 180 in pypdf/_cmap.py

View check run for this annotation

Codecov / codecov/patch

pypdf/_cmap.py#L180

Added line #L180 was not covered by tests
else:
encoding = charset_encoding["/StandardCoding"].copy()
encoding = charset_encoding["/StandardEncoding"].copy()
if "/Differences" in enc:
x: int = 0
o: Union[int, str]
Expand Down
2 changes: 1 addition & 1 deletion pypdf/_codecs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def rev_encoding(enc: List[str]) -> Dict[str, int]:


charset_encoding: Dict[str, List[str]] = {
"/StandardCoding": _std_encoding,
"/StandardEncoding": _std_encoding,
"/WinAnsiEncoding": _win_encoding,
"/MacRomanEncoding": _mac_encoding,
"/PDFDocEncoding": _pdfdoc_encoding,
Expand Down
12 changes: 12 additions & 0 deletions tests/test_cmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,15 @@ def test_binascii_odd_length_string(caplog):
page = reader.pages[0]
assert "\n(Many other theorems may\n" in page.extract_text()
assert "Skipping broken line b'143f 143f 10300': Odd-length string\n" in caplog.text


@pytest.mark.enable_socket
def test_standard_encoding(caplog):
"""Tests for #3156"""
url = "https://github.com/user-attachments/files/18983503/standard-encoding.pdf"
name = "issue3156.pdf"
reader = PdfReader(BytesIO(get_data_from_url(url, name=name)))

page = reader.pages[0]
assert page.extract_text() == "Lorem ipsum"
assert "Advanced encoding" not in caplog.text
Loading