From: cardoso_tiago@... Date: 2020-11-11T00:29:55+00:00 Subject: [ruby-core:100770] [Ruby master Misc#17309] URI.escape being deprecated, yet there is no replacement Issue #17309 has been updated by chucke (Tiago Cardoso). I may not be in position of the full details of the decision, and what is exactly the full of the deprecated URI.escape . I do have seen previous discussions on what is a URI, what's stated in the RFC, and what's the scope of the `uri` library. So far, so good. About the "my browser supports UTF-8 URLs", I think they also do what I advocate: encode the individual components of the URL into ASCII, and then DNS/TCP/HTTP it. I don't think they support something different, and they could not, for interoperability reasons. They abstract the details, though. I wonder why `uri` can't do the same. [punycode IDN domains are a standard](https://tools.ietf.org/html/rfc3492), and although `uri` doesn't support it, it could at least return a URI object with the ASCII-encoded components. The same could be said of any UTF-8 "browser URI", btw. `uri` could handle that complexity for the user, IMO. And it's more than "make an invalid URL valid"; `net-http` also allows me to pass UTF-8 strings as HTTP headers, although everything get proper encoded before going over the wire, thereby handling that implementation detail. This is my current workaround: https://gitlab.com/honeyryderchuck/httpx/-/blob/master/lib/httpx/utils.rb#L28-41 ---------------------------------------- Misc #17309: URI.escape being deprecated, yet there is no replacement https://bugs.ruby-lang.org/issues/17309#change-88413 * Author: chucke (Tiago Cardoso) * Status: Open * Priority: Normal ---------------------------------------- I'm on ruby 2.7.2 . The moment I do ```ruby uri = "http://b�cher.ch" URI.escape uri (irb):5: warning: URI.escape "http://b%C3%BCcher.ch" ``` I get that warning. Rubocop also tells me: """ URI.escape method is obsolete and should not be used. Instead, use CGI.escape, URI.encode_www_form or URI.encode_www_form_component depending on your specific use case. """ However, none of the suggestions does the same as `URI.escape`. ```ruby CGI.escape uri => "http%3A%2F%2Fb%C3%BCcher.ch" URI.encode_www_form_component uri => "http%3A%2F%2Fb%C3%BCcher.ch" URI.encode_www_form uri Traceback (most recent call last): NoMethodError (undefined method `map' for "http://b�cher.ch":String) Did you mean? tap ``` So my question is: why is this being deprecated? And if there's still reason, what to exactly replace it for, so I can keep the exact same behaviour? -- https://bugs.ruby-lang.org/ Unsubscribe: