Title: xml.sax.saxutils.XMLGenerator does not escape the namespace URI · Issue #156797 · python/cpython · GitHub
Open Graph Title: xml.sax.saxutils.XMLGenerator does not escape the namespace URI · Issue #156797 · python/cpython
X Title: xml.sax.saxutils.XMLGenerator does not escape the namespace URI · Issue #156797 · python/cpython
Description: Bug report XMLGenerator writes namespace declarations with the URI inserted as is. It is the only attribute value in this class which is not written with quoteattr(), so a URI containing &, < or a quote character produces a document whic...
Open Graph Description: Bug report XMLGenerator writes namespace declarations with the URI inserted as is. It is the only attribute value in this class which is not written with quoteattr(), so a URI containing &, < or a ...
X Description: Bug report XMLGenerator writes namespace declarations with the URI inserted as is. It is the only attribute value in this class which is not written with quoteattr(), so a URI containing &, <...
Opengraph URL: https://github.com/python/cpython/issues/156797
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"xml.sax.saxutils.XMLGenerator does not escape the namespace URI","articleBody":"# Bug report\n\n`XMLGenerator` writes namespace declarations with the URI inserted as is. It is the only attribute value in this class which is not written with `quoteattr()`, so a URI containing `&`, `\u003c` or a quote character produces a document which cannot be parsed. Copying a document with such a namespace name is enough to break it.\n\n```python\nimport io, xml.sax\nfrom xml.sax.saxutils import XMLGenerator\n\ndoc = b'\u003cp:doc xmlns:p=\"http://example.org/?a=1&b=2\">text\u003c/p:doc>'\nout = io.StringIO()\nparser = xml.sax.make_parser()\nparser.setFeature(xml.sax.handler.feature_namespaces, True)\nparser.setContentHandler(XMLGenerator(out))\nparser.parse(io.BytesIO(doc))\nprint(out.getvalue())\n```\n\nOutput:\n\n```xml\n\u003cp:doc xmlns:p=\"http://example.org/?a=1&b=2\">text\u003c/p:doc>\n```\n\nParsing it back fails with \"not well-formed (invalid token)\". The same happens for `\u003c` and for a quote character in the URI.\n\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-156799\n* gh-156856\n* gh-156857\n* gh-156858\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/serhiy-storchaka","@type":"Person","name":"serhiy-storchaka"},"datePublished":"2026-09-01T19:38:34Z","url":"https://github.com/python/cpython/issues/156797"}
| 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:356dd5cb-f4d9-4cef-0a57-7267bceec9d9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CDFA:23E48:3D88E:4CD07:6B01FA3A |
| html-safe-nonce | 1c86d4536d76664207489eb12a03790bbf2256924989798ab05be190b82e70aa |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDREZBOjIzRTQ4OjNEODhFOjRDRDA3OjZCMDFGQTNBIiwidmlzaXRvcl9pZCI6IjY3MDYwMTk0MjIxNjQ4NzU4MzQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 571617876ec401a5d78c6e8d36c802236286c08fa56c3b5a3c2c0d81aeca3a6a |
| hovercard-subject-tag | issue:5316031426 |
| 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/156797/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b28b80cf15705142fde1bc57485227a4a6add4c5d6eb418988b26f45f1b40075/python/cpython/issues/156797 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b28b80cf15705142fde1bc57485227a4a6add4c5d6eb418988b26f45f1b40075/python/cpython/issues/156797 |
| og:image:alt | Bug report XMLGenerator writes namespace declarations with the URI inserted as is. It is the only attribute value in this class which is not written with quoteattr(), so a URI containing &, < or a ... |
| 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