Skip to content

Commit 545cbc6

Browse files
committed
GH-51 : Adding a value that contains "&" in a template breaks it
1 parent 55a5b7e commit 545cbc6

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

Classes/PHPWord/Template.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,16 @@ public function setValue($search, $replace, $limit = -1)
101101
if (!PHPWord_Shared_String::IsUTF8($replace)) {
102102
$replace = utf8_encode($replace);
103103
}
104-
}
104+
$replace = htmlspecialchars($replace);
105+
} else {
106+
foreach($replace as $key=>$value) {
107+
$replace[$key] = htmlspecialchars($value);
108+
}
109+
}
105110

106111
$regExpDelim = '/';
107112
$escapedSearch = preg_quote($search, $regExpDelim);
108-
$this->_documentXML = preg_replace("{$regExpDelim}{$escapedSearch}{$regExpDelim}u",
109-
$replace,
110-
$this->_documentXML,
111-
$limit);
113+
$this->_documentXML = preg_replace("{$regExpDelim}{$escapedSearch}{$regExpDelim}u", $replace, $this->_documentXML, $limit);
112114
}
113115

114116
/**

changelog.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,20 @@
2323
**************************************************************************************
2424

2525
Changes in branch for release 0.7.1 :
26-
- Feature: (ivanlanin) GH-48 GH-86 - Table row: Repeat as header row & allow row to break across pages
27-
- Feature: (ivanlanin) GH-48 GH-86 - Table: Table width in percentage
28-
- Feature: (ivanlanin) GH-48 GH-86 - Font: Superscript and subscript
29-
- Feature: (ivanlanin) GH-48 GH-86 - Paragraph: Hanging paragraph
30-
- Feature: (ivanlanin) GH-48 GH-86 - Section: Multicolumn and section break
3126
- Bugfix: (gabrielbull) - Fixed bug with cell styling
3227
- Bugfix: (gabrielbull) - Fixed bug list items inside of cells
28+
- Bugfix: (SiebelsTim) GH-51 - Adding a value that contains "&" in a template breaks it
3329
- Feature: (RomanSyroeshko) GH-56 GH-57 - Template : Permit to save a template generated as a file (PHPWord_Template::saveAs())
3430
- Feature: (gabrielbull) - Word2007 : Support sections page numbering
3531
- Feature: (gabrielbull) - Word2007 : Added support for line height
3632
- Feature: (JillElaine) GH-5 - Word2007 : Added support for page header & page footer height
3733
- Feature: (bskrtich) GH-6 GH-66 GH-84 - General : Add ability to manage line breaks after image insertion
3834
- Feature: (RomanSyroeshko) GH-52 GH-53 GH-85 - Template : Ability to limit number of replacements performed by setValue() method of Template class
35+
- Feature: (ivanlanin) GH-48 GH-86 - Table row: Repeat as header row & allow row to break across pages
36+
- Feature: (ivanlanin) GH-48 GH-86 - Table: Table width in percentage
37+
- Feature: (ivanlanin) GH-48 GH-86 - Font: Superscript and subscript
38+
- Feature: (ivanlanin) GH-48 GH-86 - Paragraph: Hanging paragraph
39+
- Feature: (ivanlanin) GH-48 GH-86 - Section: Multicolumn and section break
3940
- QA: (Progi1984) - UnitTests
4041

4142
Changes in branch for release 0.7.0 :

0 commit comments

Comments
 (0)