python / python/planet

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

オープン
#582 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

主要言語
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. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

#577 のコミット 86e31f90403c4659471396beeba922584e08d12e の影響を受けた Python 3 のフィード生成をまず調査し、以前の 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 を短くまとめたダイジェスト。