[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
This commit is contained in:
tenma 2019-09-01 21:33:11 +01:00 committed by Diogo Cordeiro
parent 19409cb999
commit 2e66cbeb60
2 changed files with 14 additions and 8 deletions

View File

@ -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)) {

View File

@ -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];