Tail handling in addnext
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
lxml |
Fix Released
|
Medium
|
scoder |
Bug Description
Downstream issue: https:/
If elem has a tail, calling elem.addnext(elem2) inserts elem2 between elem and its tail, so this removes
elem's tail and moves it to elem2.
lxml decided that the tail belongs to the preceding element, so this relationship should stay intact over an addnext call. We're also not the first ones running into this issue, see https:/
Example code:
from lxml import etree
xml = etree.fromstrin
path = xml[0]
print(f"Tail of the first element: {path.tail}")
path.addnext(
print(f"Tail of the first element after inserting: {path.tail}")
print(f"Full tree: {etree.
Result:
Tail of the first element: tail
Tail of the first element after inserting: None
Full tree: b'<g><path/
Python : sys.version_
lxml.etree : (4, 5, 2, 0)
libxml used : (2, 9, 5)
libxml compiled : (2, 9, 5)
libxslt used : (1, 1, 30)
libxslt compiled : (1, 1, 30)
Changed in lxml: | |
status: | Fix Committed → Fix Released |
Right. This is a bug. This case was previously not covered by the test suite. I'll fix it in lxml 5.0. Thanks for the report.