From 15d8606f067e54df93061582c162ac8c82260e0b Mon Sep 17 00:00:00 2001 From: Benn Oshrin Date: Thu, 17 Apr 2025 20:43:19 -0400 Subject: [PATCH] Fix handling of HistoryRecord string truncation in UTF-8 contexts (CFM-76) --- app/src/Model/Table/HistoryRecordsTable.php | 6 +++--- app/src/Model/Table/JobHistoryRecordsTable.php | 2 +- app/src/Model/Table/PetitionHistoryRecordsTable.php | 2 +- app/src/Model/Table/ProvisioningHistoryRecordsTable.php | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/src/Model/Table/HistoryRecordsTable.php b/app/src/Model/Table/HistoryRecordsTable.php index a52334a55..04b9ae401 100644 --- a/app/src/Model/Table/HistoryRecordsTable.php +++ b/app/src/Model/Table/HistoryRecordsTable.php @@ -136,9 +136,9 @@ public function beforeMarshal(EventInterface $event, \ArrayObject $data, \ArrayO $coId = null; if(!empty($data['person_id'])) { - $coId = $this->People->findCoForRecord($data['person_id']); + $coId = $this->People->findCoForRecord((int)$data['person_id']); } elseif(!empty($data['group_id'])) { - $coId = $this->Groups->findCoForRecord($data['group_id']); + $coId = $this->Groups->findCoForRecord((int)$data['group_id']); } if($coId) { @@ -159,7 +159,7 @@ public function beforeMarshal(EventInterface $event, \ArrayObject $data, \ArrayO // Truncate the comment to fit the column width $column = $this->getSchema()->getColumn('comment'); - $data['comment'] = substr($data['comment'], 0, $column['length']); + $data['comment'] = mb_substr($data['comment'], 0, $column['length']); } } diff --git a/app/src/Model/Table/JobHistoryRecordsTable.php b/app/src/Model/Table/JobHistoryRecordsTable.php index e14273306..cc1cba7ae 100644 --- a/app/src/Model/Table/JobHistoryRecordsTable.php +++ b/app/src/Model/Table/JobHistoryRecordsTable.php @@ -112,7 +112,7 @@ public function beforeMarshal(EventInterface $event, \ArrayObject $data, \ArrayO // Truncate the comment to fit the column width $column = $this->getSchema()->getColumn('comment'); - $data['comment'] = substr($data['comment'], 0, $column['length']); + $data['comment'] = mb_substr($data['comment'], 0, $column['length']); } } diff --git a/app/src/Model/Table/PetitionHistoryRecordsTable.php b/app/src/Model/Table/PetitionHistoryRecordsTable.php index 17558c291..f552444dd 100644 --- a/app/src/Model/Table/PetitionHistoryRecordsTable.php +++ b/app/src/Model/Table/PetitionHistoryRecordsTable.php @@ -136,7 +136,7 @@ public function beforeMarshal(EventInterface $event, \ArrayObject $data, \ArrayO // Truncate the comment to fit the column width $column = $this->getSchema()->getColumn('comment'); - $data['comment'] = substr($data['comment'], 0, $column['length']); + $data['comment'] = mb_substr($data['comment'], 0, $column['length']); } } diff --git a/app/src/Model/Table/ProvisioningHistoryRecordsTable.php b/app/src/Model/Table/ProvisioningHistoryRecordsTable.php index 006049a1e..3323fb6f7 100644 --- a/app/src/Model/Table/ProvisioningHistoryRecordsTable.php +++ b/app/src/Model/Table/ProvisioningHistoryRecordsTable.php @@ -116,7 +116,7 @@ public function beforeMarshal(EventInterface $event, \ArrayObject $data, \ArrayO // Truncate the comment to fit the column width $column = $this->getSchema()->getColumn('comment'); - $data['comment'] = substr($data['comment'], 0, $column['length']); + $data['comment'] = mb_substr($data['comment'], 0, $column['length']); } }