Skip to content

Commit a3172e9

Browse files
authored
Use correct file extensions with inserted files (#1385)
* Fix boolean logic for finding file extensions * add test for correct file extension when adding ImagePart. Fixes #1305
1 parent d4445a2 commit a3172e9

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/DocumentFormat.OpenXml/Packaging/OpenXmlPart.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ private ITargetFeature GetAndVerifyTargetFeature(OpenXmlPackage openXmlPackage,
134134

135135
if (!IsContentTypeFixed)
136136
{
137-
if (!openXmlPackage.PartExtensionProvider.TryGetValue(contentType, out var found))
137+
if (openXmlPackage.PartExtensionProvider.TryGetValue(contentType, out var found))
138138
{
139139
targetExt = found;
140140
}

test/DocumentFormat.OpenXml.Tests/ofapiTest/OpenXmlPartTest.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,11 @@ public void AddPartTest()
258258
doc.AddMainDocumentPart();
259259
var document = doc.MainDocumentPart.Document = new Document();
260260
document.Save();
261+
262+
// ImagePart has correct file extension
261263
var imagePart = doc.MainDocumentPart.AddImagePart(ImagePartType.Jpeg);
264+
Assert.True(imagePart is not null && imagePart.Uri.OriginalString.EndsWith(".jpg"));
265+
262266
var extendedSubPart = doc.MainDocumentPart.AddExtendedPart("http://temp", "text/xml", ".xml", "tempId");
263267

264268
var extendedPart = doc.AddExtendedPart("http://temp", "text/xml", ".xml", "tempId");

0 commit comments

Comments
 (0)