Bug: incorrect array iteration with excluded headings
-
Hello,
Thanks for this great plugin! However, I have encountered a bug and debugged it.
In includes/class.post.php, functions excludeHeadings and removeEmptyHeadings assume that the $matches array is continuous. However, it can have holes, since removeHeadingsFromExcludedNodes and removeHeadings may unset elements.
On the page linked above I have a blog post that is partially interactive. Content is selectively shown depending on the answers of the reader. For this I use a bit of javascript. The content is in the blog post but with display:none. The content contains headers that I exclude from the table of contents using a custom css class exclude-from-toc. I have registered this class via the ez_toc_exclude_by_selector filter.
It works almost fine. Easy TOC finds all the headers, including those in the hidding content. Without my custom css class I get a TOC with the hidden headers included. I don’t want this, since the content is hidden.
When I do use my custom css class, I don’t get a TOC at all. Expected behavior: I do get a table of contents but without the excluded headers.
I found the reason why I don’t get a TOC at all:
Easy TOC finds all the headers.
Easy TOC removes the excluded headers in removeHeadingsFromExcludedNodes (in extractHeadings)
The $matches array now looks like this:
[0] -> heading #1
[1] -> heading #2
[13-19] -> heading #3-#9
etc.The total number of headings (count($matches)) is 9.
Function removeEmptyHeadings iterates only to index 9. I’m not entirely sure what happens here, but in the end $new_matches looks like this:
[0] -> heading #1
[1] -> heading #2This is fewer headers than the minimum required (4), so I get no table of contents :(.
I hope you can fix this bug! Suggestions for a work around are also appreciated.
Thanks.
The page I need help with: [log in to see the link]
The topic ‘Bug: incorrect array iteration with excluded headings’ is closed to new replies.