wc-api-ruby icon indicating copy to clipboard operation
wc-api-ruby copied to clipboard

URI.encode is obsoleted and not available in the latest Ruby versions

Open tannakartikey opened this issue 2 years ago • 4 comments

The obsolete method URI.encode is used in the code which is throwing the error while using the gem with the latest Ruby versions e.g. ruby 3.1.1p18 (2022-02-18 revision 53f5fc4236) [x86_64-linux].

https://github.com/woocommerce/wc-api-ruby/blob/64336712a87ed81269ef68bde5dcdfcfc5ec4b78/lib/woocommerce_api.rb#L100

The method was marked as obsolete many years back in 2009 with https://github.com/ruby/ruby/commit/238b979f1789f95262a267d8df6239806f2859cc

It can be replaced with the CGI.escape method.

More details: https://bugs.ruby-lang.org/issues/17309

There are many more discussions around the topic on https://bugs.ruby-lang.org/

I have monkeypatched the method in my Rails app until the patch is available on this gem.

# config/initalizers/woo_commerce.rb

module WooCommerce
  class API
    # URI.encode (alias of URI.escape) method used in the gem's implementation
    # is obsolete since 10 years and removed in Ruby 3.
    # https://github.com/ruby/ruby/commit/238b979f1789f95262a267d8df6239806f2859cc
    def add_query_params endpoint, data
      return endpoint if data.nil? || data.empty?

      endpoint += "?" unless endpoint.include? "?"
      endpoint += "&" unless endpoint.end_with? "?"
      endpoint + CGI.escape(flatten_hash(data).join("&"))
    end
  end
end

tannakartikey avatar Jul 14 '22 08:07 tannakartikey

URI.escape is also obsolete and it is used in lib/woocommerce_api.rb:100

lucas-proto avatar Jan 30 '23 10:01 lucas-proto

I have the same problem.

@tannakartikey are you working on a PR?

ricvillagrana avatar Feb 16 '24 22:02 ricvillagrana

No, I'm not. Feel free to handle if you want. Thanks.

On Sat, 17 Feb, 2024, 03:42 Ricardo Villagrana, @.***> wrote:

I have the same problem.

@tannakartikey https://github.com/tannakartikey are you working on a PR?

— Reply to this email directly, view it on GitHub https://github.com/woocommerce/wc-api-ruby/issues/57#issuecomment-1949408038, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADHFEB5WUQQ7JRIB3TK24LYT7KT3AVCNFSM53RNDMHKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOJUHE2DAOBQGM4A . You are receiving this because you were mentioned.Message ID: @.***>

tannakartikey avatar Feb 17 '24 03:02 tannakartikey

I have this problem as well. This module is broken as long as arguments are beeing passed to endpoint (which is set in querystring).

See https://github.com/woocommerce/wc-api-ruby/pull/61, this uses the updated method in URI module. Both solutions work, but please include and release, as this module is not usable anymore due to depreciation in Ruby (since 2020).

bond avatar Mar 06 '24 20:03 bond