Skip to content

Commit

Permalink
Merge pull request #6917 from radarhere/register_open
Browse files Browse the repository at this point in the history
Prevent register_open from adding duplicates to ID
  • Loading branch information
mergify[bot] committed Jan 28, 2023
2 parents 698951e + 3e37a91 commit 30010c4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
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

0 comments on commit 30010c4

Please sign in to comment.