8000 Do not decode bytes in error message · python-pillow/Pillow@231a807 · GitHub
[go: up one dir, main page]

Skip to content

Commit 231a807

Browse files
committed
Do not decode bytes in error message
1 parent 5a04b95 commit 231a807

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

Tests/test_file_ppm.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,12 +288,13 @@ def test_non_integer_token(tmp_path: Path) -> None:
288288
pass
289289

290290

291-
def test_header_token_too_long(tmp_path: Path) -> None:
291+
@pytest.mark.parametrize("data", (b"P3\x0cAAAAAAAAAA\xee", b"P6\n 01234567890"))
292+
def test_header_token_too_long(tmp_path: Path, data: bytes) -> None:
292293
path = tmp_path / "temp.ppm"
293294
with open(path, "wb") as f:
294-
f.write(b"P6\n 01234567890")
295+
f.write(data)
295296

296-
with pytest.raises(ValueError, match="Token too long in file header: 01234567890"):
297+
with pytest.raises(ValueError, match="Token too long in file header: "):
297298
with Image.open(path):
298299
pass
299300

src/PIL/PpmImagePlugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ def _read_token(self) -> bytes:
9494
msg = "Reached EOF while reading header"
9595
raise ValueError(msg)
9696
elif len(token) > 10:
97-
msg = f"Token too long in file header: {token.decode()}"
98-
raise ValueError(msg)
97+
msg_too_long = b"Token too long in file header: %s" % token
98+
raise ValueError(msg_too_long)
9999
return token
100100

101101
def _open(self) -> None:

0 commit comments

Comments
 (0)
0