Skip to content

Commit

Permalink
- [x] Fix download failed caused by control characters
Browse files Browse the repository at this point in the history
  • Loading branch information
PG-Momik committed Nov 6, 2024
1 parent 626b77b commit fbafcdf
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 201,850 deletions.
2 changes: 2 additions & 0 deletions app/Exports/ActivityExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ public function sheets(): array

$sheets[] = new OptionExport('activity_instructions', 'Instructions');

sanitizeControlCharacters($data);

foreach ($data as $key => $datum) {
$sheets[] = new XlsExport(Arr::collapse($datum), $key, $xlsHeaders[$this->sheets[$key]], 'activity');
}
Expand Down
20 changes: 20 additions & 0 deletions app/Helpers/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -1380,3 +1380,23 @@ function trimStringValueInArray($array): array
}, $array);
}
}

if (!function_exists('sanitizeControlCharacters')) {
/**
* Remove all control characters (ASCII 0x00-0x1F and 0x7F).
*
* @param $data
*
* @return void
*/
function sanitizeControlCharacters(&$data): void
{
if (is_string($data)) {
$data = preg_replace('/[\x00-\x1F\x7F]/u', '', $data);
} elseif (is_array($data)) {
foreach ($data as &$value) {
sanitizeControlCharacters($value);
}
}
}
}
2 changes: 2 additions & 0 deletions app/IATI/Elements/Xml/XmlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,8 @@ public function getXml($activity, $transaction, $result, $settings, $organizatio
$xmlData['iati-activity'] = $this->getXmlData($activity, $transaction, $result, $organization);
$xmlData['iati-activity']['@attributes'] = $this->getXmlAttributes($defaultValues, $timestamp);

sanitizeControlCharacters($xmlData);

return $this->arrayToXml->createXml('iati-activities', $xmlData);
}

Expand Down
4 changes: 4 additions & 0 deletions app/IATI/Services/Audit/AuditService.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ public function getAuditableType(object|array|string|null $auditables): string|n
*/
public function getNewValues($auditables, $auditableType, $event): bool | string
{
if (!$auditables) {
return false;
}

$auditables = $auditables->toArray();

if ($auditableType === 'App\\IATI\\Models\\User\\User' && $event !== 'signin') {
Expand Down
Loading

0 comments on commit fbafcdf

Please sign in to comment.