Skip to content

Commit

Permalink
Fix ampersand corrupting document
Browse files Browse the repository at this point in the history
  • Loading branch information
silverbackdan committed Nov 7, 2018
1 parent 1876062 commit ac6211b
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/PhpWord/Element/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class Text extends AbstractElement
*/
public function __construct($text = null, $fontStyle = null, $paragraphStyle = null)
{
// escape ampersand. It could be here because $domElement->nodeValue returns as a simple ampersand (& instead of &), or a user could have added ampersands with the addText method
$text = preg_replace('/(&)(?![0-9a-z]+;)/i', '&', $text);
$this->setText($text);
$paragraphStyle = $this->setParagraphStyle($paragraphStyle);
$this->setFontStyle($fontStyle, $paragraphStyle);
Expand Down

0 comments on commit ac6211b

Please sign in to comment.