Title: nturl2path does not use the filesystem error handler on Windows · Issue #156713 · python/cpython · GitHub
Open Graph Title: nturl2path does not use the filesystem error handler on Windows · Issue #156713 · python/cpython
X Title: nturl2path does not use the filesystem error handler on Windows · Issue #156713 · python/cpython
Description: gh-85168 made urllib.request.pathname2url() and url2pathname() use the filesystem encoding and error handler instead of forcing UTF-8, but the nturl2path module was left unchanged: "No changes are needed in the nturl2path module because ...
Open Graph Description: gh-85168 made urllib.request.pathname2url() and url2pathname() use the filesystem encoding and error handler instead of forcing UTF-8, but the nturl2path module was left unchanged: "No changes are ...
X Description: gh-85168 made urllib.request.pathname2url() and url2pathname() use the filesystem encoding and error handler instead of forcing UTF-8, but the nturl2path module was left unchanged: "No changes...
Opengraph URL: https://github.com/python/cpython/issues/156713
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"nturl2path does not use the filesystem error handler on Windows","articleBody":"gh-85168 made `urllib.request.pathname2url()` and `url2pathname()` use the filesystem encoding and error handler instead of forcing UTF-8, but the `nturl2path` module was left unchanged: \"No changes are needed in the `nturl2path` module because Windows always uses UTF-8, per PEP 529\".\n\nThat is only half true. A Windows path is a sequence of 16-bit code units, and unpaired surrogates are allowed in it. Python decodes such a name with the filesystem error handler `surrogatepass`, so the resulting string contains a lone surrogate, which `urllib.parse.quote()` cannot encode with the default `strict` handler:\n\n```pycon\n>>> import sys, nturl2path\n>>> sys.getfilesystemencoding(), sys.getfilesystemencodeerrors()\n('utf-8', 'surrogatepass')\n>>> nturl2path.pathname2url('C:\\\\a\\\\b\\udd00')\nTraceback (most recent call last):\n ...\n File \"Lib\\nturl2path.py\", line 68, in pathname2url\n tail = urllib.parse.quote(comp[1])\nUnicodeEncodeError: 'utf-8' codec can't encode character '\\udd00' in position 4: surrogates not allowed\n```\n\n`quote()` and `unquote()` should be called with `encoding=sys.getfilesystemencoding()` and `errors=sys.getfilesystemencodeerrors()`, as in `urllib.request`.\n\nIn 3.13 this is reachable through `urllib.request.pathname2url()`, which uses `nturl2path` on Windows. It is why the fix for gh-69371 cannot be backported to 3.13 as is (GH-156610 fails on Windows). Since 3.14 the module is deprecated and `urllib.request` no longer uses it, so only direct users are affected.\n\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-156717\n* gh-157423\n* gh-157424\n* gh-157425\n* gh-157461\n* gh-157462\n* gh-157464\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/serhiy-storchaka","@type":"Person","name":"serhiy-storchaka"},"datePublished":"2026-08-31T13:57:59Z","url":"https://github.com/python/cpython/issues/156713"}
| 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:624ee99f-9cda-b053-eaa5-b55cd1fedc25 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C7CC:65478:37168A7:49165D0:6B020399 |
| html-safe-nonce | 13217f649333385586d787e7f0d8b8770b9b0afc0b250760fc816b420960ffd6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDN0NDOjY1NDc4OjM3MTY4QTc6NDkxNjVEMDo2QjAyMDM5OSIsInZpc2l0b3JfaWQiOiIzNDQ3NzExMzE0MjAwMzYzOTI5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 6ac47099856587f17049cebc62dd22686a76162d0012ab5bf6290c88553293d1 |
| hovercard-subject-tag | issue:5301017959 |
| 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/156713/issue_layout |
| twitter:image | https://opengraph.githubassets.com/da21e92ac5b1d2473b901c24b9a98e931d66fe6e080cc01cfee627606f562a44/python/cpython/issues/156713 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/da21e92ac5b1d2473b901c24b9a98e931d66fe6e080cc01cfee627606f562a44/python/cpython/issues/156713 |
| og:image:alt | gh-85168 made urllib.request.pathname2url() and url2pathname() use the filesystem encoding and error handler instead of forcing UTF-8, but the nturl2path module was left unchanged: "No changes are ... |
| 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