Title: gh-74668: Fix encoded unicode in url byte string by roaanv · Pull Request #93757 · python/cpython · GitHub
Open Graph Title: gh-74668: Fix encoded unicode in url byte string by roaanv · Pull Request #93757 · python/cpython
X Title: gh-74668: Fix encoded unicode in url byte string by roaanv · Pull Request #93757 · python/cpython
Description: When urllib.parse.parse_qs is called with a byte string, an encoding can be provided which is used to decode the byte string. However, when parsing, parse.py uses 'ascii' encoding to re-encode the parsed data. This breaks utf-8 encoded URLs received as byte strings. This change uses the encoding passed to parse_qs to re-encode the parsed data. Caveat This is probably not the correct solution, but gets us closer to a working implementation that, at worst case, can be dictated by the caller of parse_qs. My understanding of the problem is as follows. parse_qs detects the qs is a byte string and decodes it according to the encoding parameter. After parsing the decoded input, it then re-encodes it (because it detected the input was a byte string), but instead of using the value of the encoding parameter, it uses 'ascii'. The decoding and encoding thus uses different encoders. This PR fixes that, in that it uses the encoding parameter value to re-encode the parsed data. However, this is not a complete solution. The problem is that there are in essence 2 encodings involved. One encoder used to encode/decode the byte string and another to encode/decode the URL (which is utf-8 encoded). Take b"a=a’b" as an example. This is a valid ascii encoded byte string and can be decoded with an ascii decoder. However, after decoding and parsing, it will not produce valid ascii. I.e. parsing of a’b will produce a’b which can not be ascii encoded. A possible solution would be to pass a reencoding parameter, but since it's unlikely callers will have different encoding and reencoding parameters, this PR opts for reusing the encoding parameter. Issue: gh-74668
Open Graph Description: When urllib.parse.parse_qs is called with a byte string, an encoding can be provided which is used to decode the byte string. However, when parsing, parse.py uses 'ascii' encoding to re-enc...
X Description: When urllib.parse.parse_qs is called with a byte string, an encoding can be provided which is used to decode the byte string. However, when parsing, parse.py uses 'ascii' encoding t...
Opengraph URL: https://github.com/python/cpython/pull/93757
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:990ff158-ba41-0308-f9d2-eed9e99ab40c |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | DC68:311382:2FA9C1:4086A0:6A4D36E4 |
| html-safe-nonce | 37fb29ec03a0374ea65c52028b2666442672d624435d2f49aa231c1d4df2401f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQzY4OjMxMTM4MjoyRkE5QzE6NDA4NkEwOjZBNEQzNkU0IiwidmlzaXRvcl9pZCI6IjI3NDUzMjYxMTkzODA5MjQxMzMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | ecef41b23517f993b4d15d943a0540294b63571fd1f0486eaf3887c703e7584e |
| hovercard-subject-tag | pull_request:965283605 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,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/python/cpython/pull/93757/files |
| twitter:image | https://avatars.githubusercontent.com/u/10389453?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/10389453?s=400&v=4 |
| og:image:alt | When urllib.parse.parse_qs is called with a byte string, an encoding can be provided which is used to decode the byte string. However, when parsing, parse.py uses 'ascii' encoding to re-enc... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 92571a8944142227b7e19cd10918b1ddd06e5066c1ad5bc7e4769cf6140a87e6 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| 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 full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 56fc8347865a14e2ec811533d68f929cf4e0ec19 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width