python / python/cpython

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

Aberta
#152,142 1 comentário 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

3.13 3.14 3.15 3.16 stdlib topic-XML type-bug
Linguagem predominante
Python
Estrelas
77.2k
Forks
35.9k
Métricas de merge de PRs
Métricas de PR pendentes

Descrição

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

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Direção de pesquisa

Comece em Lib/xml/dom/expatbuilder.py, em ExpatBuilder.notation_decl_handler, e compare-o com entity_decl_handler e os outros handlers filtrados. Adicione cobertura de DOMBuilderFilter para declarações de notação em Lib/test/test_minidom.py, usando a reprodução para verificar que as notações rejeitadas sejam omitidas e as aceitas permaneçam.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
python
Domínio
backend
Tipo de issue
Bug
Dificuldade
2/5
Tempo estimado
1-3 horas
Status de atividade
Estagnada
Clareza
Claramente especificada
Facilidade para iniciantes
35/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.