python / python/planet

The preview of the new Python 3 port has broken HTML escaping in the XML feeds

未关闭
#582 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
Python
星标
144
派生
197
PR 合并指标
30 天内没有已合并 PR

描述

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>&lt;p&gt;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

Screenshot from 2024-10-24 14-08-18

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 ?

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先检查受 #577 中提交 86e31f90403c4659471396beeba922584e08d12e 影响的 Python 3 feed 生成,比较之前的 sanitize.HTML 调用与 Markup。通过 https://planetpython.org/3/rss10.xml 验证 fix,并确认 content:encoded 中的 HTML 已进行转义,使 XML 能够在没有未定义实体错误的情况下解析。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
backend
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。