diff --git a/lib/remote_storage/riak.rb b/lib/remote_storage/riak.rb index 55435f9..c8d0c13 100644 --- a/lib/remote_storage/riak.rb +++ b/lib/remote_storage/riak.rb @@ -128,7 +128,7 @@ module RemoteStorage directory_entries(user, directory).each do |entry| timestamp = DateTime.rfc2822(entry["last_modified"]).to_i - listing.merge!({ entry["name"] => timestamp }) + listing.merge!({ CGI.unescape(entry["name"]) => timestamp }) end listing @@ -146,7 +146,8 @@ module RemoteStorage map_query = <<-EOH function(v){ keys = v.key.split(':'); - key_name = keys[keys.length-1]; + keys.splice(0, 2); + key_name = keys.join(':'); last_modified_date = v.values[0]['metadata']['X-Riak-Last-Modified']; return [{ name: key_name, diff --git a/spec/directories_spec.rb b/spec/directories_spec.rb index a1251a8..cf3a2da 100644 --- a/spec/directories_spec.rb +++ b/spec/directories_spec.rb @@ -18,7 +18,7 @@ describe "Directories" do before do put "/jimmy/tasks/foo", "do the laundry" - put "/jimmy/tasks/bar", "do the laundry" + put "/jimmy/tasks/http%3A%2F%2F5apps.com", "prettify design" end it "lists the objects with a timestamp of the last modification" do @@ -28,7 +28,7 @@ describe "Directories" do last_response.content_type.must_equal "application/json" content = JSON.parse(last_response.body) - content.must_include "bar" + content.must_include "http://5apps.com" content.must_include "foo" content["foo"].to_s.must_match /\d+/ content["foo"].to_s.length.must_be :>=, 10 @@ -62,7 +62,7 @@ describe "Directories" do content = JSON.parse(last_response.body) content.must_include "foo" - content.must_include "bar" + content.must_include "http://5apps.com" content.must_include "home/" content["home/"].to_s.must_match /\d+/ content["home/"].to_s.length.must_be :>=, 10 diff --git a/spec/riak_spec.rb b/spec/riak_spec.rb index a2d6ccb..0962337 100644 --- a/spec/riak_spec.rb +++ b/spec/riak_spec.rb @@ -174,6 +174,19 @@ describe "App with Riak backend" do end end + context "with escaped key" do + before do + put "/jimmy/documents/http%3A%2F%2F5apps.com", "super website" + end + + it "delivers the data correctly" do + header "Authorization", "Bearer 123" + get "/jimmy/documents/http%3A%2F%2F5apps.com" + + last_response.body.must_equal 'super website' + end + end + context "invalid JSON" do context "empty body" do before do