Differentiate bogus and normal comments in HTMLParser
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 35.9k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
The HTML specs support three kinds of bogus comments:
<?...>.HTMLParsercallshandle_pi()for it.<!...>.HTMLParserused to callunknown_decl()for it, but now (after #9295) it callshandle_comment().</...>if no ASCII letter follows/.HTMLParsercallshandle_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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con HTMLParser e i suoi punti di ingresso handle_pi(), handle_comment(), unknown_decl() e handle_data(), quindi esamina le alternative discusse in #9295 e #70197. Il lavoro è completato quando sono state concordate un’API e un comportamento che distinguano i commenti normali, bogus e CDATA senza compromettere gli handler esistenti.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- web-dev
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 25/100