From 8f070f53eccd0e87ca835966a332c2aa2dbea65f Mon Sep 17 00:00:00 2001 From: tenma Date: Sun, 1 Sep 2019 21:33:11 +0100 Subject: [PATCH] [CORE] Fix undefined offset warnings in different files This problem was presentend in the following issue: https://notabug.org/diogo/gnu-social/issues/60 AcceptHeader/util: - Perform isset before using the required array values --- extlib/AcceptHeader.php | 18 ++++++++++++------ lib/util.php | 4 ++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/extlib/AcceptHeader.php b/extlib/AcceptHeader.php index e146ec8231..c62ee916eb 100644 --- a/extlib/AcceptHeader.php +++ b/extlib/AcceptHeader.php @@ -49,12 +49,18 @@ class AcceptHeader extends \ArrayObject foreach ($items as $item) { $elems = explode(';', $item); - $acceptElement = []; - $mime = current($elems); - list($type, $subtype) = explode('/', $mime); - $acceptElement['type'] = trim($type); - $acceptElement['subtype'] = trim($subtype); - $acceptElement['raw'] = $mime; + $mime = current($elems); + $types = explode('/', $mime); + + if (!isset($types[1])) { + continue; + } + + $acceptElement = [ + 'raw' => $mime, + 'type' => trim($types[0]), + 'subtype' => trim($types[1]), + ]; $acceptElement['params'] = []; while (next($elems)) { diff --git a/lib/util.php b/lib/util.php index e7c92dedd0..5274045ee6 100644 --- a/lib/util.php +++ b/lib/util.php @@ -2100,7 +2100,7 @@ function common_negotiate_type($cprefs, $sprefs) foreach (array_keys($sprefs) as $type) { $parts = explode('/', $type); - if ($parts[1] != '*') { + if (isset($parts[1]) && $parts[1] != '*') { $ckey = common_mime_type_match($type, $cprefs); if ($ckey) { $combine[$type] = $sprefs[$type] * $cprefs[$ckey]; @@ -2110,7 +2110,7 @@ function common_negotiate_type($cprefs, $sprefs) foreach (array_keys($cprefs) as $type) { $parts = explode('/', $type); - if ($parts[1] != '*' && !array_key_exists($type, $sprefs)) { + if (isset($parts[1]) && $parts[1] != '*' && !array_key_exists($type, $sprefs)) { $skey = common_mime_type_match($type, $sprefs); if ($skey) { $combine[$type] = $sprefs[$skey] * $cprefs[$type];