Skip to content

Regression in OpenXmlRegex.Replace after v4.5.3 #54

@KaibutsuX

Description

@KaibutsuX

Basically when you attempt to do:

var src = "MY_VARIABLE";
OpenXmlRegex.Replace(xdoc.Descendants(W.p), new Regex("\\{\\{" + src + "\\}\\}", "REPLACED");

And the word document contains content like this:

<w:p w14:paraId="42DB84D6" w14:textId="37C824D2" w:rsidR="00C302F6" w:rsidRDefault="00722D9B" w:rsidP="00C302F6" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
  <w:pPr>
    <w:rPr>
      <w:rFonts w:eastAsia="Times New Roman" w:cstheme="minorHAnsi" />
      <w:b />
      <w:bCs />
      <w:color w:val="000000" />
    </w:rPr>
  </w:pPr>
  <w:r w:rsidRPr="00116F9B">
    <w:rPr>
      <w:rFonts w:eastAsia="Times New Roman" w:cstheme="minorHAnsi" />
      <w:b />
      <w:bCs />
      <w:color w:val="000000" />
    </w:rPr>
    <w:lastRenderedPageBreak />
    <w:t>Announcement # 2</w:t>
  </w:r>
  <w:r w:rsidR="00C302F6" w:rsidRPr="00116F9B">
    <w:rPr>
      <w:rFonts w:eastAsia="Times New Roman" w:cstheme="minorHAnsi" />
      <w:b />
      <w:bCs />
      <w:color w:val="000000" />
    </w:rPr>
    <w:t xml:space="preserve"> (Hello There</w:t>
  </w:r>
  <w:r w:rsidR="0040172E">
    <w:rPr>
      <w:rFonts w:eastAsia="Times New Roman" w:cstheme="minorHAnsi" />
      <w:b />
      <w:bCs />
      <w:color w:val="000000" />
    </w:rPr>
    <w:t>) {{MY_VARIABLE}}</w:t>
  </w:r>
</w:p>

The regex does match, but only replaces a portion, resulting in text in the word document of: (Hello ThereREPLACED}
It seems to consume the leading space and leave the trailing } character.

Using the exact same word document, same regex code and same logic, this issue is present in v4.5.3.2, but works as expected in v4.5.3.0

I'm not 100% sure, but this may be resolved by the outstanding PR: #46

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions