xml.dom.minidom: DOMBuilderFilter accept/reject is inverted for notation declarations
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 35.9k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
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
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu trong Lib/xml/dom/expatbuilder.py tại ExpatBuilder.notation_decl_handler và so sánh nó với entity_decl_handler cùng các handler được lọc khác. Thêm coverage của DOMBuilderFilter cho các khai báo notation trong Lib/test/test_minidom.py, sử dụng reproduction để xác minh rằng các notation bị từ chối được loại bỏ còn các notation được chấp nhận vẫn được giữ lại.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- backend
- Loại issue
- Lỗi
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 35/100