xml.dom.minidom: DOMBuilderFilter accept/reject is inverted for notation declarations
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 77.2k
- Forks
- 35.9k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
ExpatBuilder.notation_decl_handler in Lib/xml/dom/expatbuilder.py drops a notation when the DOMBuilderFilter accepts it and keeps it when the filter rejects it, the opposite of every other filtered handler in that file and of the DOMBuilderFilter contract (FILTER_REJECT drops the node, FILTER_ACCEPT keeps it).
import io
import xml.dom.expatbuilder as eb
from xml.dom.xmlbuilder import DOMBuilderFilter, Options
src = b'<?xml version="1.0"?><!DOCTYPE root [<!NOTATION gif PUBLIC "image/gif">]><root/>'
class RejectNotations(DOMBuilderFilter):
def acceptNode(self, node):
if node.nodeType == node.NOTATION_NODE:
return self.FILTER_REJECT
return self.FILTER_ACCEPT
def startContainer(self, node):
return self.FILTER_ACCEPT
opts = Options()
opts.filter = RejectNotations()
doc = eb.makeBuilder(opts).parseFile(io.BytesIO(src))
print(doc.doctype.notations.length) # 1 -- the filter rejected it but it was kept
The handler compares against FILTER_ACCEPT:
self.document.doctype.notations._seq.append(node)
if self._filter and self._filter.acceptNode(node) == FILTER_ACCEPT:
del self.document.doctype.notations._seq[-1]
while the sibling entity_decl_handler (and the element, comment and processing-instruction handlers) compare against FILTER_REJECT. So an accepted notation is dropped and a rejected one is kept.
Reproduces on main and on released 3.x. Lib/test/test_minidom.py has no DOMBuilderFilter coverage for notations.
Linked PRs
- gh-152143
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginnen Sie in Lib/xml/dom/expatbuilder.py bei ExpatBuilder.notation_decl_handler und vergleichen Sie ihn mit entity_decl_handler und den anderen gefilterten Handlern. Fügen Sie in Lib/test/test_minidom.py eine DOMBuilderFilter-Abdeckung für Notationsdeklarationen hinzu und verwenden Sie die Reproduktion, um zu überprüfen, dass abgelehnte Notationen weggelassen werden und akzeptierte erhalten bleiben.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- backend
- Issue-Typ
- Bug
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 35/100