Skip to content

Commit 5a16bb9

Browse files
committed
Fix object names variables
1 parent 3084fb8 commit 5a16bb9

2 files changed

Lines changed: 87 additions & 40 deletions

File tree

‎ProcessMaker/SanitizeHelper.php‎

Lines changed: 73 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,26 @@ public static function sanitizeData($data, $task)
103103
// Update database with all the exceptions ..
104104
$task->processRequest->do_not_sanitize = $except;
105105
$task->processRequest->save();
106+
106107
return self::sanitizeWithExceptions($data, $except);
107108
}
108109

109-
private static function sanitizeWithExceptions(Array $data, Array $except, $level = 0)
110+
private static function sanitizeWithExceptions(Array $data, Array $except, $parent = null)
110111
{
112+
print_r($except);
111113
foreach ($data as $key => $value) {
114+
if (!is_int($key)) {
115+
$searchKey = ($parent ? $parent . '.' . $key : $key);
116+
} else {
117+
$searchKey = $parent;
118+
}
112119
if (is_array($value)) {
113-
$data[$key] = self::sanitizeWithExceptions($value, $except, $level + 1);
120+
$data[$key] = self::sanitizeWithExceptions($value, $except, $searchKey);
114121
} else {
115122
// Only allow skipping on top-level data for now
116-
$strip_tags = !in_array($key, $except);
123+
$strip_tags = !in_array($searchKey, $except);
124+
echo $searchKey;
125+
echo $strip_tags;
117126
$data[$key] = self::sanitize($value, $strip_tags);
118127
}
119128
}
@@ -135,36 +144,76 @@ private static function getExceptions($screen)
135144
return $except;
136145
}
137146

138-
private static function getRichTextElements($items)
147+
private static function getRichTextElements($items, $parent = null)
139148
{
149+
//"loop_1.loop_2.form_text_area_2"
140150
$elements = [];
151+
141152
foreach ($items as $item) {
142153
if (isset($item['items']) && is_array($item['items'])) {
143-
// Inside a table
144-
foreach ($item['items'] as $cell) {
145-
if (
146-
isset($cell['component']) &&
147-
$cell['component'] === 'FormTextArea' &&
148-
isset($cell['config']['richtext']) &&
149-
$cell['config']['richtext'] === true
150-
) {
151-
$elements[] = $cell['config']['name'];
152-
}
153-
if (is_array($cell)) {
154-
$elements = array_merge($elements, self::getRichTextElements($cell));
155-
}
154+
if ($item['component'] == 'FormLoop') {
155+
$elements = array_merge($elements, self::getRichTextElements($item['items'], ($parent ? $parent . '.' . $item['config']['name'] : $item['config']['name'])));
156+
} else if (isset($item['component']) && $item['component'] === 'FormTextArea' && isset($item['config']['richtext']) && $item['config']['richtext'] === true) {
157+
$elements[] = ($parent ? $parent . '.' . $item['config']['name'] : $item['config']['name']);
156158
}
157159
} else {
158-
if (
159-
isset($item['component']) &&
160-
$item['component'] === 'FormTextArea' &&
161-
isset($item['config']['richtext']) &&
162-
$item['config']['richtext'] === true
163-
) {
164-
$elements[] = $item['config']['name'];
160+
if (isset($item['component']) && $item['component'] === 'FormTextArea' && isset($item['config']['richtext']) && $item['config']['richtext'] === true) {
161+
$elements[] = ($parent ? $parent . '.' . $item['config']['name'] : $item['config']['name']);
165162
}
166163
}
167164
}
165+
166+
// foreach ($items as $item) {
167+
// if (isset($item['items']) && is_array($item['items'])) {
168+
// foreach ($item['items'] as $cell) {
169+
// if ($item['component'] == 'FormLoop') {
170+
// // $path = ($parent ? $parent . '.' . $cell['config']['name'] : $item['config']['name']);
171+
// $elements = array_merge($elements, self::getRichTextElements($cell, $item['config']['name']));
172+
// } else if (
173+
// isset($cell['component']) &&
174+
// $cell['component'] === 'FormTextArea' &&
175+
// isset($cell['config']['richtext']) &&
176+
// $cell['config']['richtext'] === true
177+
// ) {
178+
// // \Log::info($path);
179+
// $elements[] = $parent . '.' . $cell['config']['name'];
180+
// }
181+
// }
182+
// }
183+
// }
184+
185+
// foreach ($items as $item) {
186+
// if (isset($item['items']) && is_array($item['items'])) {
187+
// // Inside a table
188+
// foreach ($item['items'] as $cell) {
189+
// if($item['component'] == 'FormLoop') {
190+
// // $path = ($path ? $path . '.' . $cell['config']['name'] : $item['config']['name']);
191+
// $elements = array_merge($elements, self::getRichTextElements($cell, $item));
192+
// }
193+
// if (
194+
// isset($cell['component']) &&
195+
// $cell['component'] === 'FormTextArea' &&
196+
// isset($cell['config']['richtext']) &&
197+
// $cell['config']['richtext'] === true
198+
// ) {
199+
// // \Log::info($path);
200+
// $elements[] = $path;
201+
// }
202+
// if (is_array($cell)) {
203+
// $elements = array_merge($elements, self::getRichTextElements($cell));
204+
// }
205+
// }
206+
// } else {
207+
// if (
208+
// isset($item['component']) &&
209+
// $item['component'] === 'FormTextArea' &&
210+
// isset($item['config']['richtext']) &&
211+
// $item['config']['richtext'] === true
212+
// ) {
213+
// $elements[] = $item['config']['name'];
214+
// }
215+
// }
216+
// }
168217
return $elements;
169218
}
170219

‎tests/Feature/Api/SanitizeHelperTest.php‎

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ protected function withUserSetup()
3030
$this->user->save();
3131
}
3232

33+
/**
34+
* @group agustin
35+
*/
3336
public function testSingleRichTextSanitization()
3437
{
3538
// Prepare scenario ..
@@ -48,11 +51,9 @@ public function testSingleRichTextSanitization()
4851
$response->assertJsonFragment([
4952
'do_not_sanitize' => ['form_text_area_1'],
5053
]);
51-
5254
// Assert data was sanitized or not if rich text ..
5355
$processRequest = ProcessRequest::findOrFail($this->processRequest->id)['data']['data'];
54-
55-
$this->assertEquals('<p><strong>Do not sanitize<\/strong><\/p>', $processRequest['data']['form_text_area_1']);
56+
$this->assertEquals('<p><strong>Do not sanitize<\/strong><\/p>', $processRequest['form_text_area_1']);
5657
$this->assertEquals('Sanitize', $processRequest['data']['input_1']);
5758
}
5859

@@ -104,7 +105,7 @@ public function testSingleRichTextSanitizationInsideLoop()
104105

105106
// Assert do_not_sanitize was updated successfully ..
106107
$response->assertJsonFragment([
107-
'do_not_sanitize' => ['form_text_area_3'],
108+
'do_not_sanitize' => ['loop_1.form_text_area_3'],
108109
]);
109110

110111
// Assert data was sanitized or not if rich text ..
@@ -136,7 +137,7 @@ public function testRichTextSanitizationInsideLoopInsideNestedScreen()
136137

137138
// Assert do_not_sanitize was updated successfully ..
138139
$response->assertJsonFragment([
139-
'do_not_sanitize' => ['form_text_area_4'],
140+
'do_not_sanitize' => ['loop_1.form_text_area_4'],
140141
]);
141142

142143
// Assert data was sanitized or not if rich text ..
@@ -258,17 +259,14 @@ private function createTask($processId, $screenVersionId, $processRequestId, $no
258259
private function dataSingleTask()
259260
{
260261
return [
261-
"status" => "ACTIVE",
262-
"data" => [
263-
"_user" => [
264-
"id" => 1
265-
],
266-
"_request" => [
267-
"id" => 1
268-
],
269-
"form_text_area_1" => "<p><strong>Do not sanitize<\/strong><\/p>",
270-
"input_1" => "<p><strong>Sanitize<\/strong><\/p>"
271-
]
262+
"_user" => [
263+
"id" => 1
264+
],
265+
"_request" => [
266+
"id" => 1
267+
],
268+
"form_text_area_1" => "<p><strong>Do not sanitize<\/strong><\/p>",
269+
"input_1" => "<p><strong>Sanitize<\/strong><\/p>"
272270
];
273271
}
274272

0 commit comments

Comments
 (0)