One HTML parse contract: encoding, wrapper, flags and error policy in one place
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Start with the top-level Support parsing entry points and HtmlSerialization::loadHtml() / documentHtml(); the issue identifies 84 load sites across 41 files and 4 loadXML() files. Read the current parsing and serializer paths, then trace the first slice’s candidate call sites and run the Lab gate plus the A/B output_sha256 comparison. Done means each slice uses the shared contract and reports any pages whose output changes.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Problem
The engine has no single place that defines how HTML is parsed. Each call site defines its own parse:
| Measure | Count |
|---|---|
| Load sites | 84, across 41 files |
| Encoding-hint spellings | 2: '<?xml encoding="UTF-8">' (29 sites) and '<?xml encoding="utf-8" ?>' (30). Another 20 sites get the first spelling through HtmlSerialization::utf8Document() |
| Wrappers chosen per site | 3: <body> (34), <html><body> (11), <div> (11) |
| Flags | Chosen per site: NOIMPLIED at 41 sites, NONET at 33 |
| Error policies | 3: HtmlSerialization::loadHtml() (63), @-suppression (10), LIBXML_NOERROR flags (11) |
DOMDocument construction |
2 forms: new DOMDocument() (64) and new DOMDocument('1.0', 'UTF-8') (8) |
The encoding hint is added in one place and removed in another. Each site prepends the hint when it parses. Only HtmlSerialization::documentHtml() removes it, at serialization time. As a result, the tree a caller receives depends on that call site's choices.
A local probe on libxml 2.9.13 and PHP 8.5 shows this. With LIBXML_HTML_NOIMPLIED and no wrapper element, the hint is a top-level node. A caller that walks or serializes top-level nodes therefore emits <?xml encoding="…"> along with the content, and which spelling appears depends on the call site. With a wrapper, the trees under the wrapper are identical for both spellings and both constructor forms.
Direction
Add one parse contract in top-level Support, so every layer can reach it:
- Two entry points. One parses a fragment and one parses a document. The flags follow from that choice, and
LIBXML_NONETis always on. - It owns encoding. It adds the hint, parses, and removes the hint right away, so every caller receives a clean tree.
- One error policy.
- An optional wrapper. Callers keep the
<body>,<div>or<html><body>context they need.
With that in place, documentHtml() no longer strips anything, and call sites only state what they're parsing. When the PHP floor reaches 8.4, Dom\HTMLDocument (a native HTML5 parser with native UTF-8) can replace libxml behind this one seam, and the encoding hint goes away entirely.
Slices
- Add the contract, and move the sites whose parse is provably unchanged: the same tree under a wrapper, or no top-level walk. Output must stay byte-identical.
- Move the sites where the hint currently leaks into the tree. Any output change is a fix, and each PR lists the pages whose output changed.
- Move
loadXML()(4 files) behind the same error policy, and deleteremoveEncodingHints()from the serializer path.
Each slice passes the Lab gate and the A/B output_sha256 comparison, or reports the pages whose output changed.
Part of the simplification tracker #4368.
AI disclosure: drafted by Claude Opus (Anthropic) via Pi/Roadie from source analysis and a local libxml probe, for Chris Huber.
- Ngôn ngữ chính
- PHP
- Star
- 28
- Fork
- 5
- Merge trung bình
- 2 giờ 59 phút
- Pull request đã merge (30 ngày)
- 942
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc 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.
Issue khác của Automattic/blocks-engine
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
Automattic/blocks-engine#6318 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Automattic/blocks-engine#4943 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Automattic/blocks-engine#4942 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Automattic/blocks-engine#4921 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Automattic/blocks-engine#775 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của Automattic/blocks-engine
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
TYPO3-Solr/ext-solr#4850 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[Sync EN] stream: document the errors of the stream_context_*() and stream filter functions (#6091)Đang mởsync-en
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[Sync EN] stream: document the errors of the stream_context_*() and stream filter functions (#6091)Đang mởsync-en
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Перевод устарел
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
glpi-project/glpi#26353 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày