Skip to content

Commit af6a8f7

Browse files
committed
fix: scanny#929 raises on JPEG with image/jpg MIME-type
At least one client, perhaps Adobe PDF Converter, produces a PPTX with JPEG images mapped to the non-existent `image/jpg` MIME-type rather than the correct `image/jpeg`. Accept `image/jpg` as an alias for `image/jpeg`, which is consistent with the behavior of PowerPoint which loads these files without complaint.
1 parent 284fc01 commit af6a8f7

5 files changed

Lines changed: 31 additions & 2 deletions

File tree

‎HISTORY.rst‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
Release History
44
---------------
55

6-
0.6.24-dev3
6+
0.6.24-dev4
77
+++++++++++++++++++
88

9+
- fix: #929 raises on JPEG with image/jpg MIME-type
910
- fix: #943 remove mention of a Px Length subtype
1011
- fix: #972 next-slide-id fails in rare cases
1112
- fix: #990 do not require strict timestamps for Zip
1213

14+
1315
0.6.23 (2023-11-02)
1416
+++++++++++++++++++
1517

‎features/prs-open-save.feature‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,7 @@ Feature: Round-trip a presentation
3333
When I save and reload the presentation
3434
Then the external relationships are still there
3535
And the package has the expected number of .rels parts
36+
37+
Scenario: Load presentation with invalid image/jpg MIME-type
38+
Given a presentation with an image/jpg MIME-type
39+
Then I can access the JPEG image

‎features/steps/presentation.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import io
66
import os
77
import zipfile
8+
from typing import TYPE_CHECKING, cast
89

910
from behave import given, then, when
1011
from behave.runner import Context
@@ -14,6 +15,10 @@
1415
from pptx.opc.constants import RELATIONSHIP_TYPE as RT
1516
from pptx.util import Inches
1617

18+
if TYPE_CHECKING:
19+
from pptx import presentation
20+
from pptx.shapes.picture import Picture
21+
1722
# given ===================================================
1823

1924

@@ -38,6 +43,11 @@ def given_a_presentation_having_no_notes_master(context: Context):
3843
context.prs = Presentation(test_pptx("prs-properties"))
3944

4045

46+
@given("a presentation with an image/jpg MIME-type")
47+
def given_prs_with_image_jpg_MIME_type(context):
48+
context.prs = Presentation(test_pptx("test-image-jpg-mime"))
49+
50+
4151
@given("a presentation with external relationships")
4252
def given_prs_with_ext_rels(context: Context):
4353
context.prs = Presentation(test_pptx("ext-rels"))
@@ -189,6 +199,17 @@ def then_the_package_has_the_expected_number_of_rels_parts(context: Context):
189199
assert member_count == 18, "expected 18, got %d" % member_count
190200

191201

202+
@then("I can access the JPEG image")
203+
def then_I_can_access_the_JPEG_image(context):
204+
prs = cast("presentation.Presentation", context.prs)
205+
slide = prs.slides[0]
206+
picture = cast("Picture", slide.shapes[0])
207+
try:
208+
picture.image
209+
except AttributeError:
210+
raise AssertionError("JPEG image not recognized")
211+
212+
192213
@then("the slide height matches the new value")
193214
def then_slide_height_matches_new_value(context: Context):
194215
presentation = context.presentation
32.6 KB
Binary file not shown.

‎src/pptx/__init__.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
if TYPE_CHECKING:
2626
from pptx.opc.package import Part
2727

28-
__version__ = "0.6.24-dev3"
28+
__version__ = "0.6.24-dev4"
2929

3030
sys.modules["pptx.exceptions"] = exceptions
3131
del sys
@@ -62,6 +62,8 @@
6262
CT.VIDEO: MediaPart,
6363
CT.WMV: MediaPart,
6464
CT.X_MS_VIDEO: MediaPart,
65+
# -- accommodate "image/jpg" as an alias for "image/jpeg" --
66+
"image/jpg": ImagePart,
6567
}
6668

6769
PartFactory.part_type_for.update(content_type_to_part_class_map)

0 commit comments

Comments
 (0)