samuelet / indexmenu

A dokuwiki plugin to show a customizable and sortable index for a namespace.
http://dokuwiki.org/plugin:indexmenu
GNU General Public License v2.0
44 stars 42 forks source link

PHP 8.1 error - Undefined array key 1 on line 697 #267

Closed ml17950 closed 10 months ago

ml17950 commented 1 year ago

Hi.

Problem

I'm using indexmenu (version 2022-08-01) in the sidebar with following options:

{{indexmenu>:#1|navbar nocookie notoc nomenu tsort nsort max#2 skipfile+/(footer|navigation)/}}

and get on some pages following error/warning:

Warning: Undefined array key 1 in .......\dokuwiki\lib\plugins\indexmenu\syntax\indexmenu.php on line 697

Possible Solution

replace line 697 with:

if(isset($nss[$a][1]) && ($nss[$a][1] == -1 || substr_count($match[1], ":") < $nss[$a][1])) {

Environment

Windows / Apache 2.4.56 / PHP 8.1.17 / Dokuwiki 2023-04-04a "Jack Jackrum" and 2023-06-12 "snapshot"

ksirorin commented 10 months ago

I'm also seeing similar loggings, but against line 701.

Environment

Debian 12.1 kernel 6.1.0-11-amd64
Nginx 1.22.1-9
PHP 8.2.7-1
Dokuwiki 2023-04-04a "Jack Jackrum"
Index menu  2022-08-01 (downloaded the latest master.zip from GH)

Index Plugin Config Options

$conf['plugin']['indexmenu']['skip_index'] = '/(discussion|sidebar|wiki|start|playground)/';
$conf['plugin']['indexmenu']['replace_idx'] = 'ajax';
$conf['plugin']['indexmenu']['replace_idx_depth'] = '2';

nginx/error.log

2023/09/12 01:29:06 [error] 222887#222887: *29 FastCGI sent in stderr: "; PHP message: PHP Warning:  Undefined array key 1 in /var/www/dokuwiki/lib/plugins/indexmenu/syntax/indexmenu.php on line 701; PHP message: PHP Warning:  Undefined array key 1 in /var/www/dokuwiki/lib/plugins/indexmenu/syntax/indexmenu.php on line 701; PHP message: PHP Warning:  Undefined array key 1 in /var/www/dokuwiki/lib/plugins/indexmenu/syntax/indexmenu.php on line 701; PHP message: PHP Warning:  Undefined array key 1 in /var/www/dokuwiki/lib/plugins/indexmenu/syntax/indexmenu.php on line 701; PHP message: PHP Warning:  Undefined array key 1 in /var/www/dokuwiki/lib/plugins/indexmenu/syntax/indexmenu.php on line 701; PHP message: PHP Warning:  Undefined array key 1 in /var/www/dokuwiki/lib/plugins/indexmenu/syntax/indexmenu.php on line 701; PHP message: PHP Warning:  Undefined array key 1 in /var/www/dokuwiki/lib/plugins/indexmenu/syntax/indexmenu.php on line 701; PHP message: PHP Warning:  Undefined array key 1 in /var/www/dokuwiki/lib/plugins/indexmenu/syntax/indexmenu.php on line 701; PHP message: PHP Warning:  Undefined array key 1 in /var/www/dokuwiki/lib/plugins/indexmenu/syntax/indexmenu.php on line 701; PHP message: PHP Warning:  Undefined array key 1 in /var/www/dokuwiki/lib/plugins/indexmenu/syntax/indexmenu.php on line 701; PHP message: PHP Warning:  Trying to access array offset on value of type bool in /var/www/dokuwiki/lib/plugins/indexmenu/syntax/indexmenu.php on line 916" while reading response header from upstream, client: 10.26.194.32, server: dokuwiki.server.com, request: "GET /external:about_calo:start HTTP/2.0", upstream: "fastcgi://unix:/run/php/php-fpm.sock:", host: "dokuwiki.server.com", referrer: "https://dokuwiki.server.com/external:support:start"

Lines called out from error logging in syntax/indexmenu.php

~# sed -n '701p' /var/www/dokuwiki/lib/plugins/indexmenu/syntax/indexmenu.php
                        if($nss[$a][1] == -1 || substr_count($match[1], ":") < $nss[$a][1]) {
~# sed -n '916p' /var/www/dokuwiki/lib/plugins/indexmenu/syntax/indexmenu.php
            if(!$v['hns']) array_pop($data);

If I were to pop in Martin's proposed solution and have line 701 look like:

~# sed -n '701p' /var/www/dokuwiki/lib/plugins/indexmenu/syntax/indexmenu.php
                        if(isset($nss[$a][1]) && ($nss[$a][1] == -1 || substr_count($match[1], ":") < $nss[$a][1])) {

Then the underinfed array key 1 seems to be no longer an issue (I'm assuming the type errors are just legacy php fun, other plugins have similar loggings):

2023/09/12 01:42:16 [error] 222887#222887: *36 FastCGI sent in stderr: "; PHP message: PHP Warning:  Trying to access array offset on value of type bool in /var/www/dokuwiki/lib/plugins/indexmenu/syntax/indexmenu.php on line 916" while reading response header from upstream, client: 10.26.194.32, server: dokuwiki.server.com, request: "GET /external:about_calo:start HTTP/2.0", upstream: "fastcgi://unix:/run/php/php-fpm.sock:", host: "dokuwiki.server.com", referrer: "https://dokuwiki.server.com/external:about_calo:start"
Klap-in commented 10 months ago

If using the navbar it did not set a level, fixed by explicitly setting the number of levels that should open to 1. Thanks for reporting.