Skip to content

Commit 3344ef7

Browse files
committed
When creating a OLEPropertiesContainer for the UserDefinedPropeties, use the code page from PropertySet1 instead of the one from the parent section
1 parent 7f287e6 commit 3344ef7

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

sources/OpenMcdf.Extensions/OLEProperties/OLEPropertiesContainer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ internal OLEPropertiesContainer(CFStream cfStream)
131131

132132
if (pStream.NumPropertySets == 2)
133133
{
134-
UserDefinedProperties = new OLEPropertiesContainer(this.Context.CodePage, ContainerType.UserDefinedProperties);
134+
UserDefinedProperties = new OLEPropertiesContainer(pStream.PropertySet1.PropertyContext.CodePage, ContainerType.UserDefinedProperties);
135135
this.HasUserDefinedProperties = true;
136136

137137
UserDefinedProperties.ContainerType = ContainerType.UserDefinedProperties;

sources/Test/OpenMcdf.Extensions.Test/OLEPropertiesExtensionsTest.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,5 +333,43 @@ public void Test_SUMMARY_INFO_MODIFY_LPWSTRING()
333333
}
334334
}
335335

336+
// winUnicodeDictionary.doc contains a UserProperties section with the CP_WINUNICODE codepage, and LPWSTR string properties
337+
[TestMethod]
338+
public void Test_Read_Unicode_User_Properties_Dictionary()
339+
{
340+
using (CompoundFile cf = new CompoundFile("winUnicodeDictionary.doc"))
341+
{
342+
var dsiStream = cf.RootStorage.GetStream("\u0005DocumentSummaryInformation");
343+
var co = dsiStream.AsOLEPropertiesContainer();
344+
var userProps = co.UserDefinedProperties;
345+
346+
// CodePage should be CP_WINUNICODE (1200)
347+
Assert.AreEqual(1200, userProps.Context.CodePage);
348+
349+
// There should be 5 property names present, and 6 properties (the properties include the code page)
350+
Assert.AreEqual(5, userProps.PropertyNames.Count);
351+
Assert.AreEqual(6, userProps.Properties.Count());
352+
353+
// Check for expected names and values
354+
var propArray = userProps.Properties.ToArray();
355+
356+
// CodePage prop
357+
Assert.AreEqual(1u, propArray[0].PropertyIdentifier);
358+
Assert.AreEqual("0x00000001", propArray[0].PropertyName);
359+
Assert.AreEqual((short)1200, propArray[0].Value);
360+
361+
// String properties
362+
Assert.AreEqual("A\0", propArray[1].PropertyName);
363+
Assert.AreEqual("\0", propArray[1].Value);
364+
Assert.AreEqual("AB\0", propArray[2].PropertyName);
365+
Assert.AreEqual("X\0", propArray[2].Value);
366+
Assert.AreEqual("ABC\0", propArray[3].PropertyName);
367+
Assert.AreEqual("XY\0", propArray[3].Value);
368+
Assert.AreEqual("ABCD\0", propArray[4].PropertyName);
369+
Assert.AreEqual("XYZ\0", propArray[4].Value);
370+
Assert.AreEqual("ABCDE\0", propArray[5].PropertyName);
371+
Assert.AreEqual("XYZ!\0", propArray[5].Value);
372+
}
373+
}
336374
}
337375
}
26 KB
Binary file not shown.

0 commit comments

Comments
 (0)