- Issue created by @liquidcms
- Status changed to Needs review
5 months ago 6:13pm 7 February 2024 - 🇬🇧United Kingdom John_B London (UK), Worthing (UK), Innsbruck (Tirol)
If a heading text appears twice, auto-generated IDs based on the heading text must be unique, so an -01 should be added the second time that text us used to generate an ID
Also, if the markup contains an ID which is used more than once, which is of course incorrect HTML, the second copy of the ID should be modified by the module by adding -01.
There is a bug because in certain cases the -01 is being added where it is not required.
The problem is that in src/Toc.php, the line
while (isset($this->ids[$id]) || isset($this->existingIds[$id])) {
the part
isset($this->existingIds[$id]))
is returning TRUE for IDs which are not in fact duplicates. Once that is removed, the -01 is added only where there really is a duplicate ID, or a heading with duplicate text from which we risk creating a duplicate ID. A patch is attached.Note that Drupal 10 rewrote the core HTML utility, which is used to parse HTML. There are significant differences and this can create bugs. I have not checked whether the problem arose on D9.