{"action":"created","issue":{"url":"https://api.github.com/repos/python-hyper/hyperlink/issues/16","repository_url":"https://api.github.com/repos/python-hyper/hyperlink","labels_url":"https://api.github.com/repos/python-hyper/hyperlink/issues/16/labels{/name}","comments_url":"https://api.github.com/repos/python-hyper/hyperlink/issues/16/comments","events_url":"https://api.github.com/repos/python-hyper/hyperlink/issues/16/events","html_url":"https://github.com/python-hyper/hyperlink/issues/16","id":238366753,"number":16,"title":"reserved characters are treated inconsistently and not sensibly preserved","user":{"login":"glyph","id":716529,"avatar_url":"https://avatars0.githubusercontent.com/u/716529?v=3","gravatar_id":"","url":"https://api.github.com/users/glyph","html_url":"https://github.com/glyph","followers_url":"https://api.github.com/users/glyph/followers","following_url":"https://api.github.com/users/glyph/following{/other_user}","gists_url":"https://api.github.com/users/glyph/gists{/gist_id}","starred_url":"https://api.github.com/users/glyph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/glyph/subscriptions","organizations_url":"https://api.github.com/users/glyph/orgs","repos_url":"https://api.github.com/users/glyph/repos","events_url":"https://api.github.com/users/glyph/events{/privacy}","received_events_url":"https://api.github.com/users/glyph/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":15,"created_at":"2017-06-25T08:00:36Z","updated_at":"2017-07-03T10:47:31Z","closed_at":null,"body":"This has been a design flaw since the inception of the library, so, mea culpa on that.\r\n\r\nFundamentally, preserving, escaping, and encoding \"reserved\" characters is entirely the URL object's job, and it's failing at that.  Possibly the most succinct demonstration of the problem is this:\r\n\r\n```python\r\n>>> u = URL()\r\n>>> u = u.child(u'/')\r\n>>> u = u.asIRI()\r\nTraceback (most recent call last):\r\n  File \"<input>\", line 1, in <module>\r\n    u = u.asIRI()\r\n  File\r\n\"/Users/glyph/Library/Python/2.7/lib/python/site-packages/hyperlink/_url.py\",\r\nline 1116, in to_iri\r\n    fragment=_percent_decode(self.fragment))\r\n  File\r\n\"/Users/glyph/Library/Python/2.7/lib/python/site-packages/hyperlink/_url.py\",\r\nline 861, in replace\r\n    userinfo=_optional(userinfo, self.userinfo),\r\n  File\r\n\"/Users/glyph/Library/Python/2.7/lib/python/site-packages/hyperlink/_url.py\",\r\nline 606, in __init__\r\n    for segment in path))\r\n  File\r\n\"/Users/glyph/Library/Python/2.7/lib/python/site-packages/hyperlink/_url.py\",\r\nline 606, in <genexpr>\r\n    for segment in path))\r\n  File\r\n\"/Users/glyph/Library/Python/2.7/lib/python/site-packages/hyperlink/_url.py\",\r\nline 410, in _textcheck\r\n    % (''.join(delims), name, value))\r\nValueError: one or more reserved delimiters /?# present in path segment: u'/'\r\n>>>\r\n```\r\n\r\nThis is - obviously I hope - the wrong place to be failing with an error like this.\r\n\r\nThere was previously *some* attempt to preserve these characters in the data model and escape them only upon stringification, but d26814c074c6f9787e62af907df17fbd68fde615 wrecked these semantics.  (In fairness: the attempt to do this was broken, and there are some places, like the scheme, where certain characters indeed *cannot* be represented, so this direction isn't entirely wrong.)\r\n\r\nFundamentally if a user wants to encode slashes, question marks, hash signs or whatever else that a human might, for example, type into a text field, then it should be possible to do that.\r\n\r\nWe could fix this obvious manifestation of the problem by just putting back the escape-only-on-`asText` logic, but that still leaves an even more pernicious problem:\r\n\r\n```python\r\n>>> u = URL(path=tuple([u'%2525']))\r\n>>> u.asText()\r\nu'%2525'\r\n>>> u.asIRI().asText()\r\nu'%25'\r\n>>> u.asIRI().asIRI().asText()\r\nu'%'\r\n>>> \r\n```\r\n\r\nClearly, multiple trips through `asIRI` should not be un-escaping the escape character - the idea is that `.asIRI()` is a normalization step, that should be idempotent upon subsequent calls.\r\n\r\nFor the moment, I'm not sure exactly what the correct fix is here, but the property I'd really like to preserve is that for any `x`,\r\n\r\n`URL.fromText(URL().child(x).<as many asIRI()s or asURI()s as you want>.asText()).<as many .asIRI()s as you want, although possibly not .asURI()s>.segments[0] == x`\r\n"},"comment":{"url":"https://api.github.com/repos/python-hyper/hyperlink/issues/comments/312613776","html_url":"https://github.com/python-hyper/hyperlink/issues/16#issuecomment-312613776","issue_url":"https://api.github.com/repos/python-hyper/hyperlink/issues/16","id":312613776,"user":{"login":"nigelmegitt","id":4988915,"avatar_url":"https://avatars3.githubusercontent.com/u/4988915?v=3","gravatar_id":"","url":"https://api.github.com/users/nigelmegitt","html_url":"https://github.com/nigelmegitt","followers_url":"https://api.github.com/users/nigelmegitt/followers","following_url":"https://api.github.com/users/nigelmegitt/following{/other_user}","gists_url":"https://api.github.com/users/nigelmegitt/gists{/gist_id}","starred_url":"https://api.github.com/users/nigelmegitt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nigelmegitt/subscriptions","organizations_url":"https://api.github.com/users/nigelmegitt/orgs","repos_url":"https://api.github.com/users/nigelmegitt/repos","events_url":"https://api.github.com/users/nigelmegitt/events{/privacy}","received_events_url":"https://api.github.com/users/nigelmegitt/received_events","type":"User","site_admin":false},"created_at":"2017-07-03T10:47:31Z","updated_at":"2017-07-03T10:47:31Z","body":">> OK, with this approach I cannot add a sub-path to the segment as some/path/to in one step, I have to add multiple path segments in turn. Let's trace through the impacts of allowing adding such sub-paths or not allowing it:\r\n\r\n> Indeed, this is the way that FilePath works, and URL intentionally mirrors it, for security (and other) reasons.\r\n\r\nWhat about when we just create a URL from a unicode string including all the parts? Are you saying that functionality is no longer supported?"}}
{"actor":{"display_login":"nigelmegitt"}}