diff --git a/HISTORY.rst b/HISTORY.rst index 88b6580b..73c3bace 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -3,13 +3,15 @@ Release History --------------- -0.6.24-dev3 +0.6.24-dev4 +++++++++++++++++++ +- fix: #929 raises on JPEG with image/jpg MIME-type - fix: #943 remove mention of a Px Length subtype - fix: #972 next-slide-id fails in rare cases - fix: #990 do not require strict timestamps for Zip + 0.6.23 (2023-11-02) +++++++++++++++++++ diff --git a/features/prs-open-save.feature b/features/prs-open-save.feature index 4176adfd..d60b2c24 100644 --- a/features/prs-open-save.feature +++ b/features/prs-open-save.feature @@ -33,3 +33,7 @@ Feature: Round-trip a presentation When I save and reload the presentation Then the external relationships are still there And the package has the expected number of .rels parts + + Scenario: Load presentation with invalid image/jpg MIME-type + Given a presentation with an image/jpg MIME-type + Then I can access the JPEG image diff --git a/features/steps/presentation.py b/features/steps/presentation.py index 0c1c6ba2..11a25954 100644 --- a/features/steps/presentation.py +++ b/features/steps/presentation.py @@ -5,6 +5,7 @@ import io import os import zipfile +from typing import TYPE_CHECKING, cast from behave import given, then, when from behave.runner import Context @@ -14,6 +15,10 @@ from pptx.opc.constants import RELATIONSHIP_TYPE as RT from pptx.util import Inches +if TYPE_CHECKING: + from pptx import presentation + from pptx.shapes.picture import Picture + # given =================================================== @@ -38,6 +43,11 @@ def given_a_presentation_having_no_notes_master(context: Context): context.prs = Presentation(test_pptx("prs-properties")) +@given("a presentation with an image/jpg MIME-type") +def given_prs_with_image_jpg_MIME_type(context): + context.prs = Presentation(test_pptx("test-image-jpg-mime")) + + @given("a presentation with external relationships") def given_prs_with_ext_rels(context: Context): context.prs = Presentation(test_pptx("ext-rels")) @@ -189,6 +199,17 @@ def then_the_package_has_the_expected_number_of_rels_parts(context: Context): assert member_count == 18, "expected 18, got %d" % member_count +@then("I can access the JPEG image") +def then_I_can_access_the_JPEG_image(context): + prs = cast("presentation.Presentation", context.prs) + slide = prs.slides[0] + picture = cast("Picture", slide.shapes[0]) + try: + picture.image + except AttributeError: + raise AssertionError("JPEG image not recognized") + + @then("the slide height matches the new value") def then_slide_height_matches_new_value(context: Context): presentation = context.presentation diff --git a/features/steps/test_files/test-image-jpg-mime.pptx b/features/steps/test_files/test-image-jpg-mime.pptx new file mode 100644 index 00000000..857bd7ca Binary files /dev/null and b/features/steps/test_files/test-image-jpg-mime.pptx differ diff --git a/src/pptx/__init__.py b/src/pptx/__init__.py index 0ed16055..27d6306a 100644 --- a/src/pptx/__init__.py +++ b/src/pptx/__init__.py @@ -25,7 +25,7 @@ if TYPE_CHECKING: from pptx.opc.package import Part -__version__ = "0.6.24-dev3" +__version__ = "0.6.24-dev4" sys.modules["pptx.exceptions"] = exceptions del sys @@ -62,6 +62,8 @@ CT.VIDEO: MediaPart, CT.WMV: MediaPart, CT.X_MS_VIDEO: MediaPart, + # -- accommodate "image/jpg" as an alias for "image/jpeg" -- + "image/jpg": ImagePart, } PartFactory.part_type_for.update(content_type_to_part_class_map)