From: cardoso_tiago@... Date: 2020-11-07T14:09:28+00:00 Subject: [ruby-core:100736] [Ruby master Misc#17309] URI.escape being deprecated, yet there is no replacement Issue #17309 has been updated by chucke (Tiago Cardoso). Hi Jeremy, thx for the context on the inconsistencies, that's pretty useful info. > Can you explain why "http%3A%2F%2Fb%C3%BCcher.ch" is invalid in your use case? My specific use-case is for supporting IDN domain names for HTTP requests in `httpx`, the HTTP client library I maintain (of which "b�cher.ch" is an example). Because this domain is not ascii, in order to resolve it, I have to first convert it into punycode (you can use this website (https://www.punycoder.com/) to see the translation). When using `httpx`, a user will pass the full request URL: "http://b�cher.ch" (which I know, it's not a valid URL, because it's not ASCII), so I need to, first, isolate the "host" part of this URL (or IRL), convert it to "punycode", perform the DNS resolution, then perform the HTTP request with the "host/authority" header set to "b�cher.ch". For a full functional demonstration, you can do the request with cURL and analyse it yourself. This thread I started is all about the first step, "isolating the host part of the IRL". Because the "uri" library doesn't work with IRLs , my workaround is, whenever the URL is not ascii, to: 1. use `URI.escape` to escape the domain into something URI can parse; 2. use URI() to parse into a URI::HTTP object; 3. get host, URI.unescape it, "punycode" it; 4. carry forward both domains, to perform DNS and HTTP requests; If I use `CGI.escape` or any of the suggested alternatives, the resulting escaped string isn't a URL the "uri" library can parse. And this is why I needed the deprecated `URI.escape`. ---------------------------------------- Misc #17309: URI.escape being deprecated, yet there is no replacement https://bugs.ruby-lang.org/issues/17309#change-88381 * 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: