Differentiate bogus and normal comments in HTMLParser
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 36k
- PR 合併指標
- PR 指標待擷取
描述
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
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 HTMLParser 及其 handle_pi()、handle_comment()、unknown_decl() 和 handle_data() 進入點開始,然後檢視 #9295 和 #70197 中討論的替代方案。完成的要求是確定一套一致的 API 和行為,能夠區分一般註解、bogus 註解和 CDATA 註解,同時不破壞現有的 handler。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- web-dev
- Issue 類型
- 功能
- 難度
- 5/5
- 預估耗時
- 一週以上
- 活躍度
- 停滯
- 描述清晰度
- 需要釐清
- 新手友好度
- 25/100