`HTMLParser.unknown_decl` receives corrupted data (`'CDATA['`) when parsing an empty `CDATA` section
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
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
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
Comienza ejecutando el reproductor de errores en Python del issue con HTMLParser e inspecciona la ruta de manejo de declaraciones que invoca unknown_decl. Añade cobertura para una sección CDATA vacía y verifica que el análisis produzca handle_cdata('') o la declaración desconocida completa '[CDATA[]]', en lugar de 'CDATA['.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- web-dev
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Tranquilo
- Claridad
- Bastante claro
- Aptitud para principiantes
- 65/100