steve8x8 / geotoad

Geocaching query tool written in Ruby
https://buymeacoffee.com/steve8x8
Other
28 stars 8 forks source link

Add support for Ruby 3.x (undefined method `escape' for URI:Module) #366

Closed JP95Git closed 11 months ago

JP95Git commented 3 years ago

Hi,

since Ruby 3 was released on 2020-12-25 and GeoToad doesn't say which version of Ruby is required, I tested Ruby 3.

I got this error

undefined method `escape' for URI:Module in lib/output.rb

It turns out, that URI.escape was already obsolete in Ruby 2.7 and it was removed in Ruby 3.0: https://docs.knapsackpro.com/2020/uri-escape-is-obsolete-percent-encoding-your-query-string

This is the line with URI.escape:

coord_query = URI.escape(sprintf("%.6f,%.6f", cache['latdata'].to_f, cache['londata'].to_f))

benmathews commented 2 years ago

As a workaround, revert back to ruby 2.7. For ubuntu:

sudo snap install ruby --channel=2.7/stable --classic
steve8x8 commented 2 years ago

I'm still running at Ruby 2.x (Debian Bullseye, for whatever reason, comes with 2.7). Pressure hasn't been high enough yet, and I've been busy with other projects.

I'll have another look at the issue and more - there's an occasional hiccup when GS provides a page that doesn't match the previous query, too. Stay tuned.

freswa commented 2 years ago

@steve8x8 #367 Works for ruby 2.7 and >= 3.0

steve8x8 commented 1 year ago

Thanks for confirming - while I'm using a few versions of Ruby on different platforms, I couldn't upgrade to 3.x yet, so I'd rather play safe (and have a fallback to the old way should the new one fail, e.g. because of an old Ruby version).

I think it's time to get a new version out, perhaps with #368 also addressed... to fix this and #367.

steve8x8 commented 11 months ago

Version 3.33.3, released some hours ago, incorporates the suggested change (plus a fallback to the old style, you never know...). Note that I'm still using Ruby 2.x on my two platforms, so this didn't get any real testing...