python / python/cpython

Differentiate bogus and normal comments in HTMLParser

Abierto
#137,877 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

stdlib type-feature
Lenguaje dominante
Python
Estrellas
77.2k
Forks
36k
Métricas de merge de PR
Métricas de PR pendientes

Descripción

The HTML specs support three kinds of bogus comments:

  • <?...>. HTMLParser calls handle_pi() for it.
  • <!...>. HTMLParser used to call unknown_decl() for it, but now (after #9295) it calls handle_comment().
  • </...> if no ASCII letter follows /. HTMLParser calls handle_comment() for it.

And, of course, handle_comment() is called for normal comments <!--...--> and <!--...--!>. This includes abnormal cases <!--> and <!---> which are treated as empty comment <!---->.

It is now impossible to differentiate <![if !(IE)]> from </[if !(IE)]> and <!--[if !(IE)]-->. This may be important, even if they are the same comment from the point of view of the HTML specs.

It was proposed in #70197 to add a new handler handle_bogus_comment() which calls handle_comment() by default to differentiate bogus comments from normal comments. Additional information should be passed to it besides the comment value to differentiate different kinds of bogus comments. For example, the character preceding the comment value (?, ! or /). But since handle_pi() is already called for <?...> and unknown_decl() used to be called for <!...>, we can just restore the use of unknown_decl() and add a new handler for </...>.

The second way will partially revert #9295. The difference is that a bogus comment (unknown declaration) starting with <![ will be terminated by first > instead of ]> or ]]>, in accordance to the HTML specs.

The problem is that unknown_decl() is also called for valid CDATA section (and trailing ]] is omitted). According to the HTML specs, its content should be treated as normal text, so we could simply call handle_data() (as for resolved character references), but for flexibility we can call a special method.

cc @ezio-melotti

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza con HTMLParser y sus puntos de entrada handle_pi(), handle_comment(), unknown_decl() y handle_data(), y después revisa las alternativas analizadas en #9295 y #70197. Se considera completado cuando exista una API y un comportamiento acordados que distingan entre comentarios normales, bogus y CDATA sin romper los handlers existentes.

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
Nueva funcionalidad
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Necesita aclaración
Aptitud para principiantes
25/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.