Title: Add option to validate ElementTree during serialization · Issue #149468 · python/cpython · GitHub
Open Graph Title: Add option to validate ElementTree during serialization · Issue #149468 · python/cpython
X Title: Add option to validate ElementTree during serialization · Issue #149468 · python/cpython
Description: 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 attribu...
Open Graph Description: 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 arb...
X Description: 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 esc...
Opengraph URL: https://github.com/python/cpython/issues/149468
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Add option to validate ElementTree during serialization","articleBody":"# Feature or enhancement\n\n### Proposal:\n\nElementTree can be serialized to XML and HTML formats. While special characters like `&` and `\u003c` 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 `\u003cscript>`. Also, not all characters can be represented in XML and HTML, for example the null character cannot.\n\nThis 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 `'-->\u003ctag>...\u003c/tag>\u003c!--'`.\n\nIt 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.\n\n### Has this already been discussed elsewhere?\n\nNo response given\n\n### Links to previous discussion of this feature:\n\n_No response_\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-149469\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/serhiy-storchaka","@type":"Person","name":"serhiy-storchaka"},"datePublished":"2026-05-06T19:18:48Z","url":"https://github.com/python/cpython/issues/149468"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:604eb32c-5fd9-0028-7832-5883d8022544 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D9C6:ADA9D:3B3E5FA:4BF3103:6B01FA61 |
| html-safe-nonce | b33d8a5b6a6a67e10ccc5a44264fe0e0de644dfd67900a49c51a72183a516237 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEOUM2OkFEQTlEOjNCM0U1RkE6NEJGMzEwMzo2QjAxRkE2MSIsInZpc2l0b3JfaWQiOiIxMzc4NDM5NTYxODI2NDAwODY2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 4f26cd57bded7a8c53517ec0d51c00272f34cee7327b49e35363d2802f2b1d72 |
| hovercard-subject-tag | issue:4393797392 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/149468/issue_layout |
| twitter:image | https://opengraph.githubassets.com/43a1399700ccb8ae8b1364a68df4e554230944fe2ba932254ac75f2d8ca8aa74/python/cpython/issues/149468 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/43a1399700ccb8ae8b1364a68df4e554230944fe2ba932254ac75f2d8ca8aa74/python/cpython/issues/149468 |
| og:image:alt | 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 arb... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | serhiy-storchaka |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width