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

Prevent register_open from adding duplicates to ID #6917

Merged
merged 1 commit into from
Jan 28, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions Tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,17 @@ def test_alpha_inplace(self):
with pytest.raises(ValueError):
source.alpha_composite(over, (0, 0), (0, -1))

def test_register_open_duplicates(self):
# Arrange
factory, accept = Image.OPEN["JPEG"]
id_length = len(Image.ID)

# Act
Image.register_open("JPEG", factory, accept)

# Assert
assert len(Image.ID) == id_length

def test_registered_extensions_uninitialized(self):
# Arrange
Image._initialized = 0
Expand Down
3 changes: 2 additions & 1 deletion src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -3406,7 +3406,8 @@ def register_open(id, factory, accept=None):
reject images having another format.
"""
id = id.upper()
ID.append(id)
if id not in ID:
ID.append(id)
OPEN[id] = factory, accept


Expand Down