Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft:1601-fix-download-failed-caused-control-characters #1602

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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