xml.dom.minidom: DOMBuilderFilter accept/reject is inverted for notation declarations
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 77.2k
- Forks
- 35.9k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
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
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Empieza en Lib/xml/dom/expatbuilder.py, en ExpatBuilder.notation_decl_handler, y compáralo con entity_decl_handler y los demás handlers filtrados. Añade cobertura de DOMBuilderFilter para las declaraciones de notación en Lib/test/test_minidom.py, usando la reproducción para verificar que las notaciones rechazadas se omiten y las aceptadas permanecen.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- backend
- Tipo de issue
- Error
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 35/100