From 0c1675a14390f19cef56e4d8cc1ab93d7ed74c95 Mon Sep 17 00:00:00 2001 From: Piolie Date: Thu, 4 Feb 2021 22:47:53 -0300 Subject: [PATCH 1/3] Make `formats` parameter in `Image.open` accept aNy cAsE --- Tests/test_image.py | 2 +- src/PIL/Image.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/test_image.py b/Tests/test_image.py index ade9d03c980..cff5832cfce 100644 --- a/Tests/test_image.py +++ b/Tests/test_image.py @@ -94,7 +94,7 @@ def test_open_formats(self): with pytest.raises(TypeError): Image.open(PNGFILE, formats=123) - for formats in [["JPEG"], ("JPEG",)]: + for formats in [["jPeG"], ("JpEg",)]: with pytest.raises(UnidentifiedImageError): Image.open(PNGFILE, formats=formats) diff --git a/src/PIL/Image.py b/src/PIL/Image.py index e6d3adcf748..da0d95bedd0 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -2925,7 +2925,7 @@ def _open_core(fp, filename, prefix, formats): if i not in OPEN: init() try: - factory, accept = OPEN[i] + factory, accept = OPEN[i.upper()] result = not accept or accept(prefix) if type(result) in [str, bytes]: accept_warnings.append(result) From 587e073dacdf13c94766974bd446644237887182 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 5 Feb 2021 20:28:34 +1100 Subject: [PATCH 2/3] Moved case transformation before initialization check --- src/PIL/Image.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/PIL/Image.py b/src/PIL/Image.py index da0d95bedd0..01fe7ed1bae 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -2922,10 +2922,11 @@ def open(fp, mode="r", formats=None): def _open_core(fp, filename, prefix, formats): for i in formats: + i = i.upper() if i not in OPEN: init() try: - factory, accept = OPEN[i.upper()] + factory, accept = OPEN[i] result = not accept or accept(prefix) if type(result) in [str, bytes]: accept_warnings.append(result) From 4a9a999dbb0cb6b211ca2aa6d901039ac059943e Mon Sep 17 00:00:00 2001 From: Piolie Date: Fri, 5 Feb 2021 12:21:27 -0300 Subject: [PATCH 3/3] Update Tests/test_image.py Keep the original test cases; add the most likely non-uppercase versions. Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com> --- Tests/test_image.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/test_image.py b/Tests/test_image.py index cff5832cfce..3c2d128ee73 100644 --- a/Tests/test_image.py +++ b/Tests/test_image.py @@ -94,7 +94,7 @@ def test_open_formats(self): with pytest.raises(TypeError): Image.open(PNGFILE, formats=123) - for formats in [["jPeG"], ("JpEg",)]: + for formats in [["JPEG"], ("JPEG",), ["jpeg"], ["Jpeg"], ["jPeG"], ["JpEg"]]: with pytest.raises(UnidentifiedImageError): Image.open(PNGFILE, formats=formats)