Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the regexp to avoid catastrophic backtracking #1809

Merged
merged 2 commits into from
Feb 7, 2021

Conversation

juzser
Copy link
Contributor

@juzser juzser commented Jan 21, 2020

Description

Reference Issue: #1800
Update from this PR: #1801

When you have multiple Blocks in multiple Rows, some of blocks cannot be replaced
Only the last block was replaced.
This because some word file will drop-line after xml tag, and the regular expression engine in different versions cannot find the matched block.

Fixes # (issue)
File: TemplateProcessor.php
Line: 740

Change the regexp pattern to:

'/(.*((?s)<w:p\b(?:(?!<w:p\b).)*?\${' . $blockname . '}<\/w:.*?p>))(.*)((?s)<w:p\b(?:(?!<w:p\b).)[^$]*?\${\/' . $blockname . '}<\/w:.*?p>)/is',

Describe:

  • Do not find for xml.
  • Start find the <w:p tag that closest to the blockname.
  • This <w:p does not contain any other <w:p inside it.

Checklist:

All Done

  • 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

@coveralls
Copy link

Coverage Status

Coverage remained the same at 94.633% when pulling 6087305 on JuzSer:dev-master into 733f845 on PHPOffice:develop.

@troosan troosan added this to the v0.18.0 milestone Feb 7, 2021
@troosan troosan merged commit ca45d14 into PHPOffice:develop Feb 7, 2021
@troosan troosan mentioned this pull request Apr 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants