basho/riak-ruby-client — pull request #42 by randysecrist (2012-06-21 15:36:45+00:00)
Title: Make URI escape the '+' character.

Consider the following difference in how URI and CGI handle a email address using a reserved (but allowable character) in the local part of the address:

```ruby
require 'cgi'
require 'uri'

input = 'test.foo+bar@example.com'
CGI.escape(input) => "test.foo%2Bbar%40example.com"
URI.escape(input) => "test.bar+bar@example.com"
```

URI's default rules for escaping include anything that is not a URI::PATTERN::UNRESERVED or URI::PATTERN::RESERVED character. Being within the reserved set, by default, '+' is considered safe by the URI class; however with riak, I believe it should be treated as unsafe by URI given the below test:

```bash
curl http://riakhost/buckets/users/index/email_bin/test.foo%2Bbar@example.com
{"keys":["AqV0JuwQJYlag3NQX9D6NYVo6If"]}%
curl http://riakhost/buckets/users/index/email_bin/test.foo+bar@example.com
{"keys":[]}%
```
As an alternative to this change, it is also possible to make all URI::PATTERN::UNRESERVED characters unsafe by using the following change from [netarc](https://github.com/netarc), however it does not account for the Riak.escaper abstraction already in place.

```ruby
module Riak
class Client
class HTTPBackend
def index_eq_path(bucket, index, value, options={})
raise t('indexes_unsupported') unless new_scheme?
path(riak_kv_wm_buckets, escape(bucket), "index", escape(index), URI.escape(value.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")), options)
end
end
end
end
```

Would you have any objections to making URI treat the '+' as unsafe (ensuring it is encoded)?