Skip to content

Commit a90de87

Browse files
authored
Merge pull request #6263 from ProcessMaker/bugfix/FOUR-12993
[34945] html is being sanitized in PDF connector
2 parents 1b653f4 + 1cf8d1a commit a90de87

1 file changed

Lines changed: 45 additions & 23 deletions

File tree

‎ProcessMaker/SanitizeHelper.php‎

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -188,43 +188,65 @@ private static function getExceptions($screen)
188188
return $except;
189189
}
190190

191-
private static function getRichTextElements($items, $parent = null)
191+
private static function getRichTextElements($items, $parent = null, &$elements = [])
192192
{
193-
$elements = [];
194-
195193
foreach ($items as $item) {
196194
if (isset($item['items']) && is_array($item['items'])) {
197195
// Inside loop ..
198196
if ($item['component'] == 'FormLoop') {
199-
$elements = array_merge($elements, self::getRichTextElements($item['items'], ($parent ? $parent . '.' . $item['config']['name'] : $item['config']['name'])));
200-
} elseif (isset($item['component']) && $item['component'] === 'FormTextArea' && isset($item['config']['richtext']) && $item['config']['richtext'] === true) {
201-
$elements[] = ($parent ? $parent . '.' . $item['config']['name'] : $item['config']['name']);
202-
// Inside a table ..
197+
self::getRichTextElements(
198+
$item['items'],
199+
($parent ? $parent . '.' . $item['config']['name'] : $item['config']['name']),
200+
$elements
201+
);
203202
} elseif ($item['component'] == 'FormMultiColumn') {
204-
foreach ($item['items'] as $cell) {
205-
if (
206-
isset($cell['component']) &&
207-
$cell['component'] === 'FormTextArea' &&
208-
isset($cell['config']['richtext']) &&
209-
$cell['config']['richtext'] === true
210-
) {
211-
$elements[] = $cell['config']['name'];
212-
}
213-
if (is_array($cell)) {
214-
$elements = array_merge($elements, self::getRichTextElements($cell));
215-
}
216-
}
203+
self::getVariableMultiColumn($item, $parent, $elements);
204+
} else {
205+
self::getVariableExceptions($item, $parent, $elements);
217206
}
218207
} else {
219-
if (isset($item['component']) && $item['component'] === 'FormTextArea' && isset($item['config']['richtext']) && $item['config']['richtext'] === true) {
220-
$elements[] = ($parent ? $parent . '.' . $item['config']['name'] : $item['config']['name']);
221-
}
208+
self::getVariableExceptions($item, $parent, $elements);
222209
}
223210
}
224211

225212
return $elements;
226213
}
227214

215+
private static function getVariableMultiColumn($item, $parent, &$elements)
216+
{
217+
foreach ($item['items'] as $cell) {
218+
self::getVariableExceptions($cell, $parent, $elements);
219+
if (is_array($cell)) {
220+
self::getRichTextElements($cell, $parent, $elements);
221+
}
222+
}
223+
}
224+
225+
private static function getVariableExceptions($item, $parent, &$elements)
226+
{
227+
if (!isset($item['component'])) {
228+
return;
229+
}
230+
if (self::renderHtmlIsEnabled($item, 'FormTextArea', 'richtext')) {
231+
$elements[] = ($parent ? $parent . '.' . $item['config']['name'] : $item['config']['name']);
232+
} elseif (self::renderHtmlIsEnabled($item, 'FormHtmlViewer', 'renderVarHtml')) {
233+
preg_match_all("/{{([^{}]*)}}/", $item['config']['content'], $matches);
234+
if ($matches && $matches[1]) {
235+
foreach ($matches[1] as $variable) {
236+
$elements[] = ($parent ? $parent . '.' . $variable : $variable);
237+
}
238+
}
239+
}
240+
}
241+
242+
private static function renderHtmlIsEnabled($item, $type, $field)
243+
{
244+
return isset($item['config'])
245+
&& $item['component'] === $type
246+
&& isset($item['config'][$field])
247+
&& $item['config'][$field] === true;
248+
}
249+
228250
public static function sanitizeEmail($email)
229251
{
230252
$validator = Validator::make(['email' => $email], [

0 commit comments

Comments
 (0)