Skip to content

Commit

Permalink
POI: 60293 -- Handle illegal "Odd" header/footer in XWPF
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed May 14, 2023
1 parent 416015e commit e241f51
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
13 changes: 11 additions & 2 deletions OpenXmlFormats/Wordprocessing/HdrFtr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,16 @@ public class CT_HdrFtrRef : CT_Rel
return null;
CT_HdrFtrRef ctObj = new CT_HdrFtrRef();
if (node.Attributes["w:type"] != null)
ctObj.type = (ST_HdrFtr)Enum.Parse(typeof(ST_HdrFtr), node.Attributes["w:type"].Value);
{
try
{
ctObj.type = (ST_HdrFtr)Enum.Parse(typeof(ST_HdrFtr), node.Attributes["w:type"].Value);
}
catch (ArgumentException)
{
ctObj.type = ST_HdrFtr.@default;
}
}
ctObj.id = XmlHelper.ReadString(node.Attributes["r:id"]);
return ctObj;
}
Expand Down Expand Up @@ -1904,4 +1913,4 @@ public string id
}
}
}
}
}
10 changes: 9 additions & 1 deletion testcases/ooxml/XWPF/UserModel/TestXWPFHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,5 +224,13 @@ public void TestGetPictureDataById()
{
// TODO
}
}

[Test]
public void Bug60293()
{
//test handling of non-standard header/footer options
XWPFDocument xwpf = XWPFTestDataSamples.OpenSampleDocument("60293.docx");
Assert.AreEqual(3, xwpf.HeaderList.Count);
}
}
}
Binary file added testcases/test-data/document/60293.docx
Binary file not shown.

0 comments on commit e241f51

Please sign in to comment.