Skip to content

Conversation

@tarnawski
Copy link

Description

This pull request improve REGEX used in template processing (TemplateProcessor class) in replaceBlock method.
The below example shows a case where a regular expression matches an incorrect piece of document content and after replacing causes an error during opening the file.

Current REGEX:

(<\?xml.*)(<w:p.*>\${blockname}<\/w:.*?p>)(.*)(<w:p.*\${\/blockname}<\/w:.*?p>)

current

Proposed REGEX:

(<\?xml.*)(<w:p\b.*>\${blockname}<\/w:.*?p>)(.*)(<w:p\b.*\${\/blockname}<\/w:.*?p>)

proposed

Example document content:

/word/document.xml ... <w:p> <w:pPr> <w:pStyle w:val="Normal"/> <w:widowControl w:val="false"/> <w:rPr></w:rPr> </w:pPr> <w:r> <w:rPr></w:rPr> <w:t>${keyQualifications}</w:t> </w:r> </w:p> <w:p> <w:pPr> <w:pStyle w:val="Normal"/> <w:widowControl w:val="false"/> <w:rPr></w:rPr> </w:pPr> <w:r> <w:rPr></w:rPr> <w:t>${item}</w:t> </w:r> </w:p> <w:p> <w:pPr> <w:pStyle w:val="Normal"/> <w:widowControl w:val="false"/> <w:rPr></w:rPr> </w:pPr> <w:r> <w:rPr></w:rPr> <w:t>${/keyQualifications}</w:t> </w:r> </w:p> ...

Current REGEX will result in below matches with is incorrect and lead to the wrong replacement:

<w:pStyle w:val="Normal"> ... </w:p> 

REGEX proposed in this pull request correctly matches piece of code that should be replaced:

<w:p><w:pPr><w:pStyle w:val="Normal"/> ... </w:p> 

Checklist:

  • I have run composer run-script check --timeout=0 and no errors were reported
  • The new code is covered by unit tests (check build/coverage for coverage report)
  • I have updated the documentation to describe the changes
@tarnawski
Copy link
Author

Guys, can I ask you for CR? @troosan @PowerKiKi

@tarnawski
Copy link
Author

Hello, is there anyone here?

@PowerKiKi PowerKiKi changed the base branch from develop to master November 16, 2022 21:08
@Progi1984 Progi1984 force-pushed the master branch 3 times, most recently from 2d9f999 to e458249 Compare August 30, 2023 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant