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 i=
n `httpx`, the HTTP client library I maintain (of which "b=FCcher.ch" is an=
 example).

Because this domain is not ascii, in order to resolve it, I have to first c=
onvert it into punycode (you can use this website (https://www.punycoder.co=
m/) to see the translation).

When using `httpx`, a user will pass the full request URL: "http://b=FCcher=
.ch" (which I know, it's not a valid URL, because it's not ASCII), so I nee=
d to, first, isolate the "host" part of this URL (or IRL), convert it to "p=
unycode", perform the DNS resolution, then perform the HTTP request with th=
e "host/authority" header set to "b=FCcher.ch". For a full functional demon=
stration, 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 workaro=
und 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 e=
scaped string isn't a URL the "uri" library can parse. And this is why I ne=
eded 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 =3D "http://b=FCcher.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.esca=
pe, 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
=3D> "http%3A%2F%2Fb%C3%BCcher.ch"
URI.encode_www_form_component uri
=3D> "http%3A%2F%2Fb%C3%BCcher.ch"
 URI.encode_www_form uri
Traceback (most recent call last):
NoMethodError (undefined method `map' for "http://b=FCcher.ch":String)
Did you mean?  tap
```

So my question is: why is this being deprecated? And if there's still reaso=
n, what to exactly replace it for, so I can keep the exact same behaviour?



-- =

https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=3Dunsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>