[docutils:bugs] #472 Node.previous_sibling is broken

"Günter Milde" via Docutils-develop <[email protected]>
Newsgroups gmane.text.docutils.devel
Message-ID </p/docutils/bugs/472/d52cf78c3c414b55d0d98a62d93e45ded25bd3b9.bugs@docutils.p.sourceforge.net>
- **status**: open --> closed-fixed
- **Priority**: 8 --> 5
- **Comment**:

This is a duplicate of [patches:#195], fixed in  Docutils 0.20.
Thanks for reporting, anyway.



---

**[bugs:#472] Node.previous_sibling is broken**

**Status:** closed-fixed
**Created:** Mon Jun 05, 2023 03:42 PM UTC by flying sheep
**Last Updated:** Mon Jun 05, 2023 03:53 PM UTC
**Owner:** nobody


It doesn’t work as advertised, as it never returns `None`.

~~~
def previous_sibling(self):
    """Return preceding sibling node or ``None``."""
    try:
        return self.parent[self.parent.index(self)-1]
    except (AttributeError, IndexError):
        return None
~~~

This means that when `self` is the first child, i.e. `self.parent.index(self) == 0`,  then `self.parent[-1]` is returned. The last child, not `None`. If `len(node.parent) == 1`, that means `node.previous_sibling() is node`.

This in turn means that the HTML writer for `citation` elements will emit broken HTML, see https://github.com/mcmtroffaes/sphinxcontrib-bibtex/issues/329

This is pretty severe since it leads to broken HTML markup and therefore completely broken page layout.


---

Sent from sourceforge.net because [email protected] is subscribed to https://sourceforge.net/p/docutils/bugs/

To unsubscribe from further messages, a project admin can change settings at https://sourceforge.net/p/docutils/admin/bugs/options.  Or, if this is a mailing list, you can unsubscribe from the mailing list.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.