From: Nik Okuntseff Date: Sun, 10 Mar 2019 16:40:30 +0000 (+0000) Subject: Fixed export-import of line breaks. X-Git-Tag: timetracker_1.19-1~186 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=d79981a845ee5c1e6dd404ee221d97a539f0aac8;p=timetracker.git Fixed export-import of line breaks. --- diff --git a/WEB-INF/lib/ttGroupExportHelper.class.php b/WEB-INF/lib/ttGroupExportHelper.class.php index f2290fba..9f0465d9 100644 --- a/WEB-INF/lib/ttGroupExportHelper.class.php +++ b/WEB-INF/lib/ttGroupExportHelper.class.php @@ -387,7 +387,7 @@ class ttGroupExportHelper { $log_part .= " task_id=\"".$this->taskMap[$record['task_id']]."\""; $log_part .= " timesheet_id=\"".$this->timesheetMap[$record['timesheet_id']]."\""; $log_part .= " invoice_id=\"".$this->invoiceMap[$record['invoice_id']]."\""; - $log_part .= " comment=\"".htmlspecialchars($record['comment'])."\""; + $log_part .= " comment=\"".$this->encodeLineBreaks($record['comment'])."\""; $log_part .= " billable=\"".$record['billable']."\""; $log_part .= " approved=\"".$record['approved']."\""; $log_part .= " paid=\"".$record['paid']."\""; @@ -459,7 +459,7 @@ class ttGroupExportHelper { $expense_item_part .= " user_id=\"".$this->userMap[$expense_item['user_id']]."\""; $expense_item_part .= " client_id=\"".$this->clientMap[$expense_item['client_id']]."\""; $expense_item_part .= " project_id=\"".$this->projectMap[$expense_item['project_id']]."\""; - $expense_item_part .= " name=\"".htmlspecialchars($expense_item['name'])."\""; + $expense_item_part .= " name=\"".$this->encodeLineBreaks($expense_item['name'])."\""; $expense_item_part .= " cost=\"".$expense_item['cost']."\""; $expense_item_part .= " invoice_id=\"".$this->invoiceMap[$expense_item['invoice_id']]."\""; $expense_item_part .= " approved=\"".$expense_item['approved']."\""; @@ -495,7 +495,7 @@ class ttGroupExportHelper { foreach ($templates as $template) { $template_part = $this->indentation.' '."\n"; fwrite($this->file, $template_part); @@ -634,4 +634,18 @@ class ttGroupExportHelper { fwrite($this->file, $this->indentation."\n"); } + + // encodeLineBreaks encodes line breaks with an escape sequence. + // We do this, because our strings are attribute values inside XML tags. + // + // If we don't, we lose line breaks after importing data because + // XML parser converts line breaks into a single white character. + // + // TODO: investigate whether we need to encode \t, etc. + private function encodeLineBreaks($source) { + $result = htmlspecialchars($source); + $result = str_replace ("\n", ' ', $result); + $result = str_replace ("\r", ' ', $result); + return $result; + } } diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index a6bbd639..a624fe1b 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.18.56.4855 | Copyright © Anuko | +  Anuko Time Tracker 1.18.57.4856 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve}