Issue #17309 has been updated by jeremyevans0 (Jeremy Evans).


Maybe @naruse can describe the reason it was deprecated over 11 years ago i=
n commit:238b979f1789f95262a267d8df6239806f2859cc.  In my opinion, as the o=
ne who changed the deprecation warning from verbose mode to always in 2.7 a=
nd removed the method in 3.0, it has various issues. The API is a bit too e=
asy to misuse, as `URI.escape(' ', 'UTF-8')` returns `' '`.  It doesn't esc=
ape URL query parameters as you would expect: `URI.escape(' ')` is `'%20'` =
and not `'+'`.  It uses an RFC 2396 parser and not an RFC 3986 parser, so `=
URI.escape('[]')` is `'[]'` and not `'%5B%5D'`.  Both `CGI.escape` and `URI=
.encode_www_form_component` are probably better general-purpose escaping me=
thods.  I generally prefer `CGI.escape` as it is written in C and should be=
 significantly faster.

Can you explain why `"http%3A%2F%2Fb%C3%BCcher.ch"` is invalid in your use =
case?

For exactly the same behavior you can use `URI::DEFAULT_PARSER.escape(str)`.

----------------------------------------
Misc #17309: URI.escape being deprecated, yet there is no replacement
https://bugs.ruby-lang.org/issues/17309#change-88377

* 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>