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

fix: #929 raises on JPEG with image/jpg MIME-type #996

Merged
merged 1 commit into from
Aug 3, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
+++++++++++++++++++

Expand Down
4 changes: 4 additions & 0 deletions features/prs-open-save.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 21 additions & 0 deletions features/steps/presentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ===================================================


Expand All @@ -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"))
Expand Down Expand Up @@ -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
Expand Down
Binary file not shown.
4 changes: 3 additions & 1 deletion src/pptx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down