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

TemplateProcessor cloneBlock wrongly clones images #1763

Merged

Conversation

alarai
Copy link

@alarai alarai commented Nov 28, 2019

Description

I was met with the issue reported in #1750 and fixed it.
The problem was that the regexp to clone and add number did include the size attributes in the tag before the number. So I added a second capture group so that image attributes are properly placed after the tag with it's added number.

I also fixed the call to Process to use an array as it otherwise cause hundred of errors as it now expects an array instead of a string.

All tests are passed and code coverage is unchanged.

Fixes #1750 #1624

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

… part after the #number and fixing Process call to array instead of string
@coveralls
Copy link

coveralls commented Nov 28, 2019

Coverage Status

Coverage remained the same at 94.619% when pulling d9cb88e on TimeTonic:fixes-1750-block-with-images-inside into 5a7a11a on PHPOffice:develop.

@troosan troosan changed the title Fixes #1750 image in cloneblock TemplateProcessor cloneblock wrongly clones images Dec 15, 2019
@troosan troosan added this to the v0.18.0 milestone Dec 15, 2019
@@ -1085,7 +1085,7 @@ protected function indexClonedVariables($count, $xmlBlock)
{
$results = array();
for ($i = 1; $i <= $count; $i++) {
$results[] = preg_replace('/\$\{(.*?)\}/', '\${\\1#' . $i . '}', $xmlBlock);
$results[] = preg_replace('/\$\{([^:]*?)(:.*?)?\}/', '\${\1#' . $i . '\2}', $xmlBlock);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just wondering why you're only using one \ compared to the old regex and to my changes in #1829:

$results[] = preg_replace('/\$\{(.*?)(:([^}])*)?\}/', '\${\\1#' . $i . '\\2}', $xmlBlock);

I'm not that much into this regex at the moment, so I don't know how they differ.

btw, this pr will also fix #1624

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Amerlander that's because in a single quoted string you don't have to double the
https://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.single

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for explanation and for the merge! :)

@troosan troosan changed the title TemplateProcessor cloneblock wrongly clones images TemplateProcessor cloneBlock wrongly clones images Feb 7, 2021
@troosan troosan merged commit bf8f2ac into PHPOffice:develop Feb 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

cloneBlock with images inside
4 participants