python / python/cpython

xml.dom.minidom: DOMBuilderFilter accept/reject is inverted for notation declarations

オープン
#152,142 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

3.13 3.14 3.15 3.16 stdlib topic-XML type-bug
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

ExpatBuilder.notation_decl_handler in Lib/xml/dom/expatbuilder.py drops a notation when the DOMBuilderFilter accepts it and keeps it when the filter rejects it, the opposite of every other filtered handler in that file and of the DOMBuilderFilter contract (FILTER_REJECT drops the node, FILTER_ACCEPT keeps it).

import io
import xml.dom.expatbuilder as eb
from xml.dom.xmlbuilder import DOMBuilderFilter, Options

src = b'<?xml version="1.0"?><!DOCTYPE root [<!NOTATION gif PUBLIC "image/gif">]><root/>'

class RejectNotations(DOMBuilderFilter):
    def acceptNode(self, node):
        if node.nodeType == node.NOTATION_NODE:
            return self.FILTER_REJECT
        return self.FILTER_ACCEPT
    def startContainer(self, node):
        return self.FILTER_ACCEPT

opts = Options()
opts.filter = RejectNotations()
doc = eb.makeBuilder(opts).parseFile(io.BytesIO(src))
print(doc.doctype.notations.length)   # 1 -- the filter rejected it but it was kept

The handler compares against FILTER_ACCEPT:

self.document.doctype.notations._seq.append(node)
if self._filter and self._filter.acceptNode(node) == FILTER_ACCEPT:
    del self.document.doctype.notations._seq[-1]

while the sibling entity_decl_handler (and the element, comment and processing-instruction handlers) compare against FILTER_REJECT. So an accepted notation is dropped and a rejected one is kept.

Reproduces on main and on released 3.x. Lib/test/test_minidom.py has no DOMBuilderFilter coverage for notations.

Linked PRs
  • gh-152143

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

Lib/xml/dom/expatbuilder.py の ExpatBuilder.notation_decl_handler から始め、entity_decl_handler やその他のフィルタリングされたハンドラーと比較します。Lib/test/test_minidom.py に記法宣言に対する DOMBuilderFilter のカバレッジを追加し、再現コードを使って、拒否された記法が省略され、受け入れられた記法が残ることを確認します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
backend
issue の種類
バグ
難易度
2/5
見積もり時間
1〜3時間
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。