bugsnag / bugsnag-api-ruby

BugSnag API toolkit for Ruby
Other
21 stars 15 forks source link

undefined method `escape' with URI:Module for Ruby 3.x #31

Closed godric closed 3 years ago

godric commented 3 years ago

Describe the bug

The gem calls URI.escape in Bugsnag::Client#request: https://github.com/bugsnag/bugsnag-api-ruby/blob/bccaf4b4f3811d3a415ff2ce2649df996cf0bbbe/lib/bugsnag/api/client.rb#L188

This method is obsolete: it raises a warning in 2.7.x and has been removed in 3.x. Escaping methods from CGI.escape should be used instead, see https://ruby-doc.org/stdlib-2.7.1/libdoc/uri/rdoc/URI/Escape.html#method-i-escape-label-Description

Be warned that CGI.escape and URI.escape produce different results, especially with the / char, eg:

URI.encode("foo/bar") # "foo/bar"
CGI.encode("foo/bar") # "foo%2Fbar"

Steps to reproduce

  1. Install Ruby 3.x
  2. Perform a request to any endpoint
  3. See the NoMethodError being raised, ie:
    NoMethodError:
    undefined method `escape' for URI:Module

Environment

Workaround

Patch the method back into URI, ie:

module URI
  def self.escape(str, unsafe = URI::UNSAFE)
    str.gsub(unsafe, &CGI.method(:escape))
  end
end
johnkiely1 commented 3 years ago

Hi @godric, Thanks for this. We are already aware of this and are looking into it. It has been raised here previously. https://github.com/bugsnag/bugsnag-api-ruby/pull/28. I will close this as we are tracking it via the pull request.