`HTMLParser.unknown_decl` receives corrupted data (`'CDATA['`) when parsing an empty `CDATA` section
オープン
まだ誰も着手していません。
3.13
3.14
3.15
stdlib
type-bug
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
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
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、HTMLParser を使って issue の Python 再現コードを実行し、unknown_decl を呼び出す宣言処理の経路を調査します。空の CDATA セクションのカバレッジを追加し、パースの結果が 'CDATA[' ではなく、handle_cdata('') または完全な未知の宣言 '[CDATA[]]' のいずれかになることを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- web-dev
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 静か
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 65/100