Title: Recommended practice for adding reserved characters? · Issue #44 · python-hyper/hyperlink · GitHub
Open Graph Title: Recommended practice for adding reserved characters? · Issue #44 · python-hyper/hyperlink
X Title: Recommended practice for adding reserved characters? · Issue #44 · python-hyper/hyperlink
Description: Per @markrwilliams comment here and a few others dotted around, we're facing a design gap in hyperlink's APIs. To paraphrase: url = URL() url.add(u'param', u'#value').to_text() Yields: ValueError: one or more reserved delimiters prese...
Open Graph Description: Per @markrwilliams comment here and a few others dotted around, we're facing a design gap in hyperlink's APIs. To paraphrase: url = URL() url.add(u'param', u'#value').to_text() Yields: ValueError: ...
X Description: Per @markrwilliams comment here and a few others dotted around, we're facing a design gap in hyperlink's APIs. To paraphrase: url = URL() url.add(u'param', u'#value').to_tex...
Opengraph URL: https://github.com/python-hyper/hyperlink/issues/44
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Recommended practice for adding reserved characters?","articleBody":"Per @markrwilliams comment [here](https://github.com/python-hyper/hyperlink/issues/6#issuecomment-338984058) and a few others dotted around, we're facing a design gap in hyperlink's APIs. \r\n\r\nTo paraphrase:\r\n```\r\nurl = URL()\r\nurl.add(u'param', u'#value').to_text()\r\n```\r\nYields:\r\n```\r\nValueError: one or more reserved delimiters present in query parameter value: u'#value'\r\n```\r\n\r\nThis is due to a subtle shift in hyperlink's design compared to `twisted.python.url`. `t.p.url` would allow any string value in, whereas hyperlink prefers to store the \"minimally-encoded\" version. This is why a `ValueError` is raised from the code above.\r\n\r\nTechnically, this can be solved by making the code `url.add(u'param', _encode_query_part(u'#value'))`. But hyperlink's primary goal is to handle encoding/decoding, does it really make sense to push that back on the user?\r\n\r\nOne solution Mark and I discussed would be to switch to decoding every value passed in. But what if someone were to pass in `u'%23%'` and actually intend for that to be their decoded value? And the API would be further complicated by the fact that the underlying decoding is generally unknown. UTF8, Latin-1, and plain old binary are all valid in percent-encoded URL parts. Autodecoding UTF8 might have better usability most of the time, but much like relying on Python 2's implicit encoding/decoding, the safety of the explicit `_encode_*_part()` is probably preferable.\r\n\r\nIt might occur to one that this entire problem bears some resemblance to the `bytes`/`unicode` split, as `URL` has `URL.to_uri()` and `URL.to_iri()`. There is some truth to this, but both IRIs and URIs are both URLs. Having two types imposes a sort of artificial split I'd like to avoid if possible, but we also don't have a good way to represent an already decoded IRI. This was causing an issue with double decoding on multiple `.to_iri()` calls (see #16). \r\n\r\nRight now my best idea is to enable that technical solution above by exposing the various encoding and decoding functions as public APIs, since those may prove useful utilities for other contexts anyways. I'm sure there are better ideas, too, so I'm going to leave this issue open as a place for discussion on handling this quandary.","author":{"url":"https://github.com/mahmoud","@type":"Person","name":"mahmoud"},"datePublished":"2017-10-26T17:45:40Z","url":"https://github.com/python-hyper/hyperlink/issues/44"}
| 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:feb9d46c-2272-bd31-5ce1-11b49496dac1 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AB88:DD526:EF00E4:146AECD:6B06F134 |
| html-safe-nonce | 1ff484517b6f4e6ff817cb7c10341e832c124626af646f61370835d90fb89f37 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQjg4OkRENTI2OkVGMDBFNDoxNDZBRUNEOjZCMDZGMTM0IiwidmlzaXRvcl9pZCI6Ijc1MjIwNjg2ODQ0ODg1MDM2MDQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | ed19f88b7077b77edb252e61d2e14dc39dc72f377eb52f07ed42e22dd2b4ef0f |
| hovercard-subject-tag | issue:268850644 |
| 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-hyper/hyperlink/44/issue_layout |
| twitter:image | https://opengraph.githubassets.com/afd8650e398c0c65ce2c6ba6b8606bc972eb3e8176c06ff04677a44fe5a2f85a/python-hyper/hyperlink/issues/44 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/afd8650e398c0c65ce2c6ba6b8606bc972eb3e8176c06ff04677a44fe5a2f85a/python-hyper/hyperlink/issues/44 |
| og:image:alt | Per @markrwilliams comment here and a few others dotted around, we're facing a design gap in hyperlink's APIs. To paraphrase: url = URL() url.add(u'param', u'#value').to_text() Yields: ValueError: ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mahmoud |
| hostname | github.com |
| expected-hostname | github.com |
| None | 351ea5ca38a5758919d44ee52c70fe9003c0c2dfa20f04effd7fac0c5330c16b |
| turbo-cache-control | no-preview |
| go-import | github.com/python-hyper/hyperlink git https://github.com/python-hyper/hyperlink.git |
| octolytics-dimension-user_id | 13035907 |
| octolytics-dimension-user_login | python-hyper |
| octolytics-dimension-repository_id | 82321340 |
| octolytics-dimension-repository_nwo | python-hyper/hyperlink |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 82321340 |
| octolytics-dimension-repository_network_root_nwo | python-hyper/hyperlink |
| 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 | 891bde3f438884e9c6c7ccd826f33805910a978b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width