Empty list is returned on DTD attributes

Bug #1266171 reported by Removed by request
6
Affects Status Importance Assigned to Milestone
lxml
Fix Released
Medium
scoder

Bug Description

The following code returns an empty attribute list on the DTD element test but it has an attribute in the xml document:

#!/usr/bin/python3 -BEOObbs
# coding=utf-8

import io, lxml.etree

xml = lxml.etree.parse(io.BytesIO(b'''<?xml
 version='1.1'
 encoding='utf-8'
?>
<!DOCTYPE root [
 <!ATTLIST test
  attr (A | B | C) 'B'
 >
 <!ELEMENT test (#PCDATA)>
 <!ELEMENT root (test)*>
]>
<root></root>'''))
element = xml.docinfo.internalDTD.elements()[0]
print(element.name)
print(element.attributes())

This is the output:

sworddragon@ubuntu:~/tmp$ ./test.py
test
[]

Used versions:

Python : sys.version_info(major=3, minor=3, micro=3, releaselevel='final', serial=0)
lxml.etree : (3, 3, 0, -98)
libxml used : (2, 9, 1)
libxml compiled : (2, 9, 1)
libxslt used : (1, 1, 28)
libxslt compiled : (1, 1, 28)

Revision history for this message
scoder (scoder) wrote :

Thanks for the report and the test code. I can confirm this, and it applies only to internal/external subsets, not DTDs parsed independently. Working on a fix.

Changed in lxml:
assignee: nobody → scoder (scoder)
importance: Undecided → Medium
status: New → Confirmed
Revision history for this message
scoder (scoder) wrote :
Changed in lxml:
status: Confirmed → Fix Committed
Revision history for this message
scoder (scoder) wrote :

This is better as it additionally avoids keeping the document itself alive:

https://github.com/lxml/lxml/commit/3923cb727ac2cc0a5e4152ed42071be8a323fa5b

Revision history for this message
scoder (scoder) wrote :

Fixed in lxml 3.3.0.

Changed in lxml:
milestone: none → 3.3
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.