Phpword: TemplateProcessor::fixBrokenMacros stripping more than it should

Created on 7 Apr 2017  路  5Comments  路  Source: PHPOffice/PHPWord

TemplateProcessor::fixBrokenMacros picking up '$' dollar characters and strip_tags every thing after it breaking formatting

I Changed the regex to '|\$[{]{[^}]}|U' which seems to work in my use case.

Repeatable by putting a '$' symbol on its own. Anything beyond that will get bunched up together or corrupt the outputted word document.


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Most helpful comment

I had the same issue and struggled with it for a while. Your fix didn't seem to work for me, but what I ended up doing was replacing the '$' with the numeric character reference with a str_replace in the constructor before sending to the fixBrokenMacros function.

It's hacky but if someone else struggles with the same problem my solution was replacing this

$this->tempDocumentMainPart = $this->fixBrokenMacros($this->zipClass->getFromName($this->getMainPartName()));

with this

$text = str_replace('${','${',str_replace('$', '$', $this->zipClass->getFromName($this->getMainPartName())));
$this->tempDocumentMainPart = $this->fixBrokenMacros($text);

in the constructor of TemplateProcessor.

I don't want to touch my search-patterns (macros), so I change those back afterwards, also allowing the fixBrokenMacros function to work if i.e no end tag was given.

Ref numeric character references:

All 5 comments

I had the same issue and struggled with it for a while. Your fix didn't seem to work for me, but what I ended up doing was replacing the '$' with the numeric character reference with a str_replace in the constructor before sending to the fixBrokenMacros function.

It's hacky but if someone else struggles with the same problem my solution was replacing this

$this->tempDocumentMainPart = $this->fixBrokenMacros($this->zipClass->getFromName($this->getMainPartName()));

with this

$text = str_replace('${','${',str_replace('$', '$', $this->zipClass->getFromName($this->getMainPartName())));
$this->tempDocumentMainPart = $this->fixBrokenMacros($text);

in the constructor of TemplateProcessor.

I don't want to touch my search-patterns (macros), so I change those back afterwards, also allowing the fixBrokenMacros function to work if i.e no end tag was given.

Ref numeric character references:

@jt6a74 Your regex worked for me 馃憤

@Shakagi Thnks a lot. It works for me 馃憤

Worked for me too. Thanks!

my fix seems to be simply removing the call to fixBrokenMacros.

$this->tempDocumentMainPart = $this->zipClass->getFromName($this->getMainPartName());
// $this->tempDocumentMainPart = $this->fixBrokenMacros($this->zipClass->getFromName($this->getMainPartName()));
Was this page helpful?
0 / 5 - 0 ratings

Related issues

akashraiesoft picture akashraiesoft  路  4Comments

dwalker109 picture dwalker109  路  6Comments

fishwolf picture fishwolf  路  4Comments

Joel-James picture Joel-James  路  3Comments

cyrillkalita picture cyrillkalita  路  6Comments