Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tannakartikey opened this issue Jul 14, 2022 · 4 comments · May be fixed by #61
Open

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

tannakartikey opened this issue Jul 14, 2022 · 4 comments · May be fixed by #61

Comments

@tannakartikey
Copy link

tannakartikey commented Jul 14, 2022

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].

endpoint + URI.encode(flatten_hash(data).join("&"))

The method was marked as obsolete many years back in 2009 with ruby/ruby@238b979

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
@lucas-proto
Copy link

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

@ricvillagrana
Copy link

I have the same problem.

@tannakartikey are you working on a PR?

@ricvillagrana ricvillagrana linked a pull request Feb 16, 2024 that will close this issue
@tannakartikey
Copy link
Author

tannakartikey commented Feb 17, 2024 via email

@bond
Copy link

bond commented Mar 6, 2024

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 #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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants