qoobaa/s3 — pull request #62 by jakepaul (2012-03-03 23:30:20+00:00)
Title: Escape non-unreserved characters in URIs

Calling `temporary_url` on an object with brackets in its key throws an exception caused by `URI.parse` in S3::Signature.canonicalized_resource:

URI::InvalidURIError: bad URI(is not URI?): /johnsmith/photos/puppy%20[1].jpg
/Users/jakepaul/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/uri/common.rb:156:in `split'
/Users/jakepaul/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/uri/common.rb:174:in `parse'
/Users/jakepaul/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/uri/common.rb:628:in `parse'
/Users/jakepaul/Projects/s3/lib/s3/signature.rb:217:in `canonicalized_resource'
/Users/jakepaul/Projects/s3/lib/s3/signature.rb:105:in `canonicalized_signature'
/Users/jakepaul/Projects/s3/lib/s3/signature.rb:60:in `generate_temporary_url_signature'

The reason is URI.escape doesn't encode certain "non-unreserved" characters by default, such as square brackets. Details: http://bugs.ruby-lang.org/issues/3457

The workaround is to specify a less-inclusive regex when calling URI.escape on certain parts of a URL (the resource key in this case).