qoobaa / s3

Library for accessing S3 objects and buckets, supports EU and US buckets
MIT License
258 stars 112 forks source link

URI escape invalid #132

Open kallisti5 opened 2 years ago

kallisti5 commented 2 years ago
/home/kallisti5/.gem/ruby/3.0.0/gems/s3-0.3.29/lib/s3/bucket.rb:154:in `list_bucket': undefined method `escape' for URI:Module (NoMethodError)
    from /home/kallisti5/.gem/ruby/3.0.0/gems/s3-0.3.29/lib/s3/bucket.rb:115:in `block in objects'
    from /home/kallisti5/.gem/ruby/3.0.0/gems/proxies-0.2.3/lib/proxies/proxy.rb:58:in `proxy_target'
    from /home/kallisti5/.gem/ruby/3.0.0/gems/proxies-0.2.3/lib/proxies/proxy.rb:62:in `method_missing'
    from ./nightly-reaper-s3.rb:37:in `<main>'
qoobaa commented 2 years ago

Yeah, it seems some changes are required in order to launch it on Ruby 3.0.

Could you create a PR?

kallisti5 commented 2 years ago

I was able to work around the issue locally:

--- /home/kallisti5/.gem/ruby/3.0.0/gems/s3-0.3.29/lib/s3/bucket.rb.original    2022-02-18 13:26:37.247078560 -0600
+++ /home/kallisti5/.gem/ruby/3.0.0/gems/s3-0.3.29/lib/s3/bucket.rb 2022-02-18 13:26:47.707146732 -0600
@@ -151,7 +151,7 @@
       # If there are more than 1000 objects S3 truncates listing and
       # we need to request another listing for the remaining objects.
       while parse_is_truncated(response.body)
-        next_request_options = {:marker => URI.escape(objects_attributes.last[:key])}
+        next_request_options = {:marker => URI::DEFAULT_PARSER.escape(objects_attributes.last[:key])}

         if max_keys
           break if objects_attributes.length >= max_keys

That's likely not a good fix though since it might break for Ruby 2.x / stdlib 2.x.

Really surprised Ruby didn't leave some compatibility .escape call in the api :-|

kallisti5 commented 2 years ago

I opened https://bugs.ruby-lang.org/issues/18593 maybe the real solution is Ruby 3.x should have been less aggressive in refactoring escape :-)