From 9641d1364b9cd93d0325ca2dccfaa3e50126310f Mon Sep 17 00:00:00 2001 From: Eduardo M KALINOWSKI Date: Wed, 8 Jun 2022 09:06:35 -0300 Subject: PHP8 compatibility htmlspecialchars() complains about null argument, so a null-safe wrapper was added. --- dmarcts-report-viewer-common.php | 9 +++++++++ dmarcts-report-viewer-report-data.php | 2 +- dmarcts-report-viewer-report-list.php | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/dmarcts-report-viewer-common.php b/dmarcts-report-viewer-common.php index 7fdc542..2a16d12 100644 --- a/dmarcts-report-viewer-common.php +++ b/dmarcts-report-viewer-common.php @@ -349,6 +349,15 @@ function format_date($date, $format) { return $answer; }; +// null-safe version of htmlspecialchars for PHP 8+ compatibility +// -------------------------------------------------------------------------- +function html_escape($str) { + if ($str == null) { + return null; + } + return htmlspecialchars($str); +} + // Get all configuration options // -------------------------------------------------------------------------- function configure() { diff --git a/dmarcts-report-viewer-report-data.php b/dmarcts-report-viewer-report-data.php index 5aae830..0b542ef 100644 --- a/dmarcts-report-viewer-report-data.php +++ b/dmarcts-report-viewer-report-data.php @@ -144,7 +144,7 @@ ORDER BY } /* escape html characters after exploring binary values, which will be messed up */ - $row = array_map('htmlspecialchars', $row); + $row = array_map('html_escape', $row); $reportdata[] = " "; $reportdata[] = " ". $ip. ""; diff --git a/dmarcts-report-viewer-report-list.php b/dmarcts-report-viewer-report-list.php index d07b107..9062197 100644 --- a/dmarcts-report-viewer-report-list.php +++ b/dmarcts-report-viewer-report-list.php @@ -73,7 +73,7 @@ function tmpl_reportList($reports, $sort) { $reportsum = 0; foreach ($reports as $row) { - $row = array_map('htmlspecialchars', $row); + $row = array_map('html_escape', $row); $reportlist[] = " "; $reportlist[] = " " . get_dmarc_result($row)['status_sort_key'] . ""; // Col 0 -- cgit v1.2.3