EvotecIT / OfficeIMO

Fast and easy to use cross-platform .NET library that creates or modifies Microsoft Word (DocX) and later also Excel (XLSX) files without installing any software. Library is based on Open XML SDK
MIT License
279 stars 49 forks source link

Reading distributed/interrupted instructions of field codes causes an exception #94

Closed byteSamurai closed 1 year ago

byteSamurai commented 1 year ago

I just stumbled upon an issue. Given this markup from a off-the-shelf Word document:

<w:r w:rsidR="006B53C8">
    <w:fldChar w:fldCharType="begin" />
</w:r>
<w:r w:rsidR="006B53C8">
    <w:instrText xml:space="preserve"> XE "</w:instrText>
</w:r>
<w:r w:rsidR="006B53C8" w:rsidRPr="00D01158">
    <w:instrText>Introduction</w:instrText>
</w:r>
<w:r w:rsidR="006B53C8">
    <w:instrText xml:space="preserve">" </w:instrText>
</w:r>
<w:r w:rsidR="006B53C8">
    <w:fldChar w:fldCharType="end" />
</w:r>

From the document:

Expected Behaviour

The instruction text will be concatenated to form the string XE "Introduction"

Actual Behaviour

An Exception will be thrown, because the detected fieldCode is just XE ":

Unhandled exception. System.NotImplementedException: The missing part """ of the field code "XE "" couldn't be processed by the Parser
   at OfficeIMO.Word.WordFieldParser.ParseFieldCodeDeclaration(String fieldCodeDeclaration) in /home/f/OfficeIMO/OfficeIMO.Word/WordFieldParser.cs:line 118
   at OfficeIMO.Word.WordFieldParser..ctor(String fieldCodeDeclaration) in /home/f/OfficeIMO/OfficeIMO.Word/WordFieldParser.cs:line 56
   at OfficeIMO.Word.WordField.get_FieldType() in /home/f/OfficeIMO/OfficeIMO.Word/WordField.cs:line 107

Possible Fix Suggestions

PrzemyslawKlys commented 1 year ago

Option 1, of course.

byteSamurai commented 1 year ago

Okay, on it.

PrzemyslawKlys commented 1 year ago

Tests would be good for this case. Leaving it open unless you think it's not needed.