python / python/cpython

xml.dom.minidom: DOMBuilderFilter accept/reject is inverted for notation declarations

Aperta
#152,142 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

3.13 3.14 3.15 3.16 stdlib topic-XML type-bug
Lingua principale
Python
Stelle
77.2k
Fork
35.9k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia in Lib/xml/dom/expatbuilder.py da ExpatBuilder.notation_decl_handler e confrontalo con entity_decl_handler e con gli altri handler filtrati. Aggiungi la copertura di DOMBuilderFilter per le dichiarazioni di notazione in Lib/test/test_minidom.py, usando la riproduzione per verificare che le notazioni rifiutate vengano omesse e che quelle accettate rimangano.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
backend
Tipo di issue
Bug
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.