ssahara / dw-plugin-toctweak

Implement different mechanism for table of contents (TOC)
https://www.dokuwiki.org/plugin:toctweak
1 stars 3 forks source link

TypeError thrown by sidebar TOC when accessing deleted page #14

Open pyuxiang opened 1 year ago

pyuxiang commented 1 year ago

When accessing a deleted page, i.e. by removing page contents, the following error message is thrown by PHP:

TypeError: Cannot access offset of type string on string

An unforeseen error has occured. This is most likely a bug somewhere. It might be a problem in the toctweak plugin.

More info has been written to the DokuWiki error log.
Dump of Dokuwiki error log ``` 2022-12-26 11:51:31 /var/www/dokuwiki/lib/plugins/toctweak/helper.php(96) TypeError: Cannot access offset of type string on string #0 /var/www/dokuwiki/lib/plugins/toctweak/syntax/sidetoc.php(73): helper_plugin_toctweak->get_metatoc() #1 /var/www/dokuwiki/inc/parser/renderer.php(117): syntax_plugin_toctweak_sidetoc->render() #2 /var/www/dokuwiki/inc/parserutils.php(682): Doku_Renderer->plugin() #3 /var/www/dokuwiki/inc/parserutils.php(149): p_render() #4 /var/www/dokuwiki/inc/parserutils.php(89): p_cached_output() #5 /var/www/dokuwiki/inc/template.php(1585): p_wiki_xhtml() #6 /var/www/dokuwiki/lib/tpl/dokuwiki/main.php(43): tpl_include_page() #7 /var/www/dokuwiki/inc/actions.php(27): include('...') #8 /var/www/dokuwiki/doku.php(126): act_dispatch() #9 {main} ```

Cause seems to be due to $INFO['meta'] array being unpopulated for such deleted pages,

array(9) { ["date"]=> string(0) "" ["creator"]=> string(0) "" ["user"]=> string(0) "" ["last_change"]=> string(0) "" ["contributor"]=> string(0) "" ["title"]=> string(0) "" ["description"]=> string(0) "" ["relation"]=> string(0) "" ["internal"]=> string(0) "" }


This issue does not manifest when the page itself has not been previously created, nor did it appear in Dokuwiki Hogfather running PHP 7.4 (Ubuntu 20.04).

Environment:

pyuxiang commented 1 year ago

Resolution is relatively straightfoward - replace the if-else condition in lines 95-99 of $DOKUWIKI/lib/plugins/toctweak/helper.php:

https://github.com/ssahara/dw-plugin-toctweak/blob/6fea3566234b5fbe9894d6abe407afe23d537454/helper.php#L95-L100

with just the else-clause from line 98:

$toc = p_get_metadata($id,'description tableofcontents'); 

When the tableofcontents variable is dynamically retrieved, the $toc will be assigned null and immediately exits the TOC render function. Not sure what side-effects there are, so leaving it as a comment.