python / python/cpython

Add option to validate ElementTree during serialization

Offen
#149,468 5 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

stdlib topic-XML type-feature
Vorherrschende Sprache
Python
Sterne
77.2k
Forks
35.9k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

Feature or enhancement

Proposal:

ElementTree can be serialized to XML and HTML formats. While special characters like & and < are escaped in text and attribute values, there is no way to escape arbitrary characters in element and attribute names, comments, processing instructions and HTML elements like <script>. Also, not all characters can be represented in XML and HTML, for example the null character cannot.

This is usually not a problem, because the structure of the element tree is usually hardcoded and variable parts have reasonable values. But if the element tree is constructed using arbitrary user data, it is possible to inject some elements. For example, if the comment is '--><tag>...</tag><!--'.

It is considered the user's responsibility to ensure that the element tree is valid. But we can help them. The proposed PR add the validate option to serialization functions which enables validation if true. It is the option of serialization because rules are different for XML and HTML.

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Linked PRs
  • gh-149469

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit den XML- und HTML-Serialisierungsfunktionen von ElementTree und prüfe den verknüpften PR gh-149469, der als Implementierung dieses Vorschlags identifiziert ist. Als abgeschlossen gilt die Aufgabe, wenn die Serialisierung die vorgeschlagene Validierungsoption akzeptiert und die entsprechenden Validierungsregeln für XML und HTML anwendet, einschließlich der hier beschriebenen Zeichen- und Injection-Fälle.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
backend
Issue-Typ
Feature
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.