Skip to content

Commit

Permalink
Merge pull request #111 from Numpsy/rw/dictionary_code_page
Browse files Browse the repository at this point in the history
When creating a OLEPropertiesContainer for the UserDefinedPropeties, …
  • Loading branch information
ironfede authored Feb 21, 2024
2 parents 7f287e6 + 3344ef7 commit 3cbd645
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ internal OLEPropertiesContainer(CFStream cfStream)

if (pStream.NumPropertySets == 2)
{
UserDefinedProperties = new OLEPropertiesContainer(this.Context.CodePage, ContainerType.UserDefinedProperties);
UserDefinedProperties = new OLEPropertiesContainer(pStream.PropertySet1.PropertyContext.CodePage, ContainerType.UserDefinedProperties);
this.HasUserDefinedProperties = true;

UserDefinedProperties.ContainerType = ContainerType.UserDefinedProperties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,5 +333,43 @@ public void Test_SUMMARY_INFO_MODIFY_LPWSTRING()
}
}

// winUnicodeDictionary.doc contains a UserProperties section with the CP_WINUNICODE codepage, and LPWSTR string properties
[TestMethod]
public void Test_Read_Unicode_User_Properties_Dictionary()
{
using (CompoundFile cf = new CompoundFile("winUnicodeDictionary.doc"))
{
var dsiStream = cf.RootStorage.GetStream("\u0005DocumentSummaryInformation");
var co = dsiStream.AsOLEPropertiesContainer();
var userProps = co.UserDefinedProperties;

// CodePage should be CP_WINUNICODE (1200)
Assert.AreEqual(1200, userProps.Context.CodePage);

// There should be 5 property names present, and 6 properties (the properties include the code page)
Assert.AreEqual(5, userProps.PropertyNames.Count);
Assert.AreEqual(6, userProps.Properties.Count());

// Check for expected names and values
var propArray = userProps.Properties.ToArray();

// CodePage prop
Assert.AreEqual(1u, propArray[0].PropertyIdentifier);
Assert.AreEqual("0x00000001", propArray[0].PropertyName);
Assert.AreEqual((short)1200, propArray[0].Value);

// String properties
Assert.AreEqual("A\0", propArray[1].PropertyName);
Assert.AreEqual("\0", propArray[1].Value);
Assert.AreEqual("AB\0", propArray[2].PropertyName);
Assert.AreEqual("X\0", propArray[2].Value);
Assert.AreEqual("ABC\0", propArray[3].PropertyName);
Assert.AreEqual("XY\0", propArray[3].Value);
Assert.AreEqual("ABCD\0", propArray[4].PropertyName);
Assert.AreEqual("XYZ\0", propArray[4].Value);
Assert.AreEqual("ABCDE\0", propArray[5].PropertyName);
Assert.AreEqual("XYZ!\0", propArray[5].Value);
}
}
}
}
Binary file not shown.

0 comments on commit 3cbd645

Please sign in to comment.