diff options
author | Eduardo M KALINOWSKI <eduardo@kalinowski.com.br> | 2022-06-08 15:06:35 +0300 |
---|---|---|
committer | Eduardo M KALINOWSKI <eduardo@kalinowski.com.br> | 2022-06-08 15:06:35 +0300 |
commit | 9641d1364b9cd93d0325ca2dccfaa3e50126310f (patch) | |
tree | 81854dcc0e1dc8a54c1906c40ba834b30bdd36a0 | |
parent | 749dfb1d6294268fc7a683a6577478bab60f8847 (diff) |
PHP8 compatibility
htmlspecialchars() complains about null argument, so a null-safe
wrapper was added.
-rw-r--r-- | dmarcts-report-viewer-common.php | 9 | ||||
-rw-r--r-- | dmarcts-report-viewer-report-data.php | 2 | ||||
-rw-r--r-- | 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[] = " <tr id='line" . $row['id'] . "' class='" . get_dmarc_result($row)['color'] . "' title='DMARC Result: " . get_dmarc_result($row)['result'] . "' onmouseover='highlight(this);' onmouseout='unhighlight(this);' onclick='pin(this);'>"; $reportdata[] = " <td>". $ip. "</td>"; 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[] = " <tr class='linkable' onclick=\"showReport('" . $row['serial'] . "')\" id='report" . $row['serial'] . "' title='" . $title_message_tr . "'>"; $reportlist[] = " <td class='circle_container'><span class='status_sort_key'>" . get_dmarc_result($row)['status_sort_key'] . "</span></td>"; // Col 0 |