`HTMLParser.unknown_decl` receives corrupted data (`'CDATA['`) when parsing an empty `CDATA` section
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Python
- Estrelas
- 77.2k
- Forks
- 36k
- Métricas de merge de PRs
- Métricas de PR pendentes
Descrição
Bug report
Bug description:
When parsing the input <![CDATA[]]>, the unknown_decl hook is incorrectly called with the corrupted, partial string 'CDATA['.
A correct parser has only two possible-and-correct behaviors:
- If CDATA is supported: Call
handle_cdata(''). - If the declaration is "unrecognized," the
unknown_declhook must receive the entire content inside<!...>, which would be'[CDATA[]]'.
The actual result ('CDATA[') matches neither of those. I use the private _set_support_cdata(True) method here since I think it was the only available trigger to activate this specific code path to expose the bug.
from html.parser import HTMLParser
class CdataBugParser(HTMLParser):
def __init__(self):
super().__init__()
self.unknown_decls = []
def unknown_decl(self, data):
self.unknown_decls.append(data)
html_input = "<![CDATA[]]>"
parser = CdataBugParser()
parser._set_support_cdata(True)
parser.feed(html_input)
print(parser.unknown_decls)
['CDATA[']
CPython versions tested on:
3.12
Operating systems tested on:
Linux
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Comece executando o reprodutor Python da issue com HTMLParser e inspecione o caminho de tratamento de declarações que invoca unknown_decl. Adicione cobertura para uma seção CDATA vazia e verifique se o parsing produz handle_cdata('') ou a declaração desconhecida completa '[CDATA[]]', em vez de 'CDATA['.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- python
- Domínio
- web-dev
- Tipo de issue
- Bug
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Status de atividade
- Pouca atividade
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 65/100