The preview of the new Python 3 port has broken HTML escaping in the XML feeds
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 144
- Fork
- 197
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
I am using:
O.S: Fedora 40
Browser: Firefox 131.0.2
Platform: desktop
Problem
The preview of the new Python 3 port has broken HTML escaping in the XML feeds
eg try to view this in the browser:
https://planetpython.org/3/rss10.xml
and it will complain about undefined entities, due to having raw unescaped HTML in the XML document
By comparison the original Python 2 code escaped HTML in the feed
$ wget https://planetpython.org/rss10.xml
$ grep "content:encoded" rss10.xml | head -1
<content:encoded><p>As is probably apparent from the sequence of blog posts about the topic in the
$ wget https://planetpython.org/3/rss10.xml
$ grep "content:encoded" rss10.xml.1 | head -1
<content:encoded><p>As is probably apparent from the sequence of blog posts about the topic in the
Details
This problem is caused by a mistake in the python 3 conversion done in #577, specially in commit https://github.com/python/planet/pull/577/commits/86e31f90403c4659471396beeba922584e08d12e replaced code patterns like:
feed[key] = sanitize.HTML(feed[key])
with
feed[key] = Markup(feed[key])
which is not providing functionally equivalent behaviour.
The sanitize.HTML method would parse the HTML and strip out various undesirable elements and attributes, and escaping was later performed by the template processor.
The Markup method will not parse anything, it'll just wrap the str in a Markup class, as a way to designate it as being safe to use as-is without further escaping. As a result when you later try to escape the variable in jinga using ... | e, it will do nothing at all, resulting in raw HTML being put into the XML document, leading to the later parsing errors.
I think either the original sanitizer code needs to be re-instated and made to work with py3, or perhaps an external library such as https://github.com/matthiask/html-sanitizer/ could be leveraged ?
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
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 bằng việc kiểm tra quá trình tạo feed Python 3 bị ảnh hưởng bởi commit 86e31f90403c4659471396beeba922584e08d12e trong #577, so sánh lệnh gọi sanitize.HTML trước đây với Markup. Xác minh fix tại https://planetpython.org/3/rss10.xml và xác nhận rằng HTML trong content:encoded được escape để XML có thể được phân tích mà không gặp lỗi entity chưa được định nghĩa.
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ó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 45/100