From 4e017cbef04f4623bf0147f31da45ce3bcd0f0ab Mon Sep 17 00:00:00 2001 From: demeritcowboy Date: Thu, 7 May 2020 17:12:59 -0400 Subject: [PATCH] fix decoding of apostrophes --- CRM/Report/Utils/Report.php | 2 +- tests/phpunit/CRM/Report/Utils/ReportTest.php | 72 +++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 tests/phpunit/CRM/Report/Utils/ReportTest.php diff --git a/CRM/Report/Utils/Report.php b/CRM/Report/Utils/Report.php index 627c2a97c7..e2ca8de213 100644 --- a/CRM/Report/Utils/Report.php +++ b/CRM/Report/Utils/Report.php @@ -251,7 +251,7 @@ WHERE inst.report_id = %1"; $value = $row[$v] ?? NULL; if (isset($value)) { // Remove HTML, unencode entities, and escape quotation marks. - $value = str_replace('"', '""', html_entity_decode(strip_tags($value))); + $value = str_replace('"', '""', html_entity_decode(strip_tags($value), ENT_QUOTES | ENT_HTML401)); if (CRM_Utils_Array::value('type', $form->_columnHeaders[$v]) & 4) { if (CRM_Utils_Array::value('group_by', $form->_columnHeaders[$v]) == 'MONTH' || diff --git a/tests/phpunit/CRM/Report/Utils/ReportTest.php b/tests/phpunit/CRM/Report/Utils/ReportTest.php new file mode 100644 index 0000000000..68326f7cdb --- /dev/null +++ b/tests/phpunit/CRM/Report/Utils/ReportTest.php @@ -0,0 +1,72 @@ +_columnHeaders = [ + 'civicrm_activity_activity_type_id' => [ + 'title' => 'Activity Type', + 'type' => 2, + ], + 'civicrm_activity_activity_subject' => [ + 'title' => 'Subject', + 'type' => 2, + ], + 'civicrm_activity_details' => [ + 'title' => 'Activity Details', + 'type' => NULL, + ], + ]; + + $details = <<Here's some typical data from an activity details field. +

+

дè some non-ascii and html styling and these ̋“weird” quotes’s. +

+

Also some named entities "hello". And & é. Also some math like 2 < 4. +

+ENDDETAILS; + + $expectedOutput = << 'Meeting', + 'civicrm_activity_activity_subject' => 'Meeting with the apostrophe\'s and that person who does "air quotes". Some non-ascii characters: дè', + 'civicrm_activity_details' => $details, + ], + ]; + + $csvString = CRM_Report_Utils_Report::makeCsv($form, $rows); + $this->assertEquals($expectedOutput, $csvString); + } + +} -- 2.25.1