Comments/PIs before doctype are lost
Bug #1421921 reported by
Olli Pottonen
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
lxml |
Fix Released
|
Low
|
Olli Pottonen |
Bug Description
>>> import lxml.etree
>>> doc = lxml.etree.
>>> etree.tostring(doc)
Expected result:
'<!--foo-
actual result:
'<!DOCTYPE a>\n<a/>'
Version info:
Python : sys.version_
libxml used : (2, 8, 0)
libxml compiled : (2, 8, 0)
libxslt used : (1, 1, 26)
libxslt compiled : (1, 1, 26)
To post a comment you must log in.
The comment is parsed correctly and doc.getroottree ().getprevious( ) returns it as expected. The bug is in serialization. _writePrevSibli ngs() in serializer.pxi omits declaration (as it should) and everything before it (as it should not).
Because lxml handles the declaration itself, instead of relying on libxml2, this is difficult to get right.