diff --git a/lib/remote_storage/riak.rb b/lib/remote_storage/riak.rb index 2ef3c39..248da41 100644 --- a/lib/remote_storage/riak.rb +++ b/lib/remote_storage/riak.rb @@ -270,14 +270,19 @@ module RemoteStorage map_query = <<-EOH function(v){ - keys = v.key.split(':'); - keys.splice(0, 2); - key_name = keys.join(':'); - last_modified_date = v.values[0]['metadata']['X-Riak-Last-Modified']; - timestamp = v.values[0]['metadata']['X-Riak-Meta']['X-Riak-Meta-Timestamp']; - etag = v.values[0]['metadata']['X-Riak-VTag']; + var metadata = v.values[0]['metadata']; + var dir_name = metadata['index']['directory_bin']; + if (dir_name === '/') { + dir_name = ''; + } + var name = v.key.match(/^[^:]*:(.*)/)[1]; // strip username from key + name = name.replace(dir_name + ':', ''); // strip directory from key + var last_modified_date = metadata['X-Riak-Last-Modified']; + var timestamp = metadata['X-Riak-Meta']['X-Riak-Meta-Timestamp']; + var etag = metadata['X-Riak-VTag']; + return [{ - name: key_name, + name: name, last_modified: last_modified_date, timestamp: timestamp, etag: etag @@ -294,12 +299,12 @@ module RemoteStorage map_query = <<-EOH function(v){ - keys = v.key.split(':'); - key_name = keys[keys.length-1]; - timestamp = v.values[0]['data']; - etag = v.values[0]['metadata']['X-Riak-VTag']; + var name = v.key.match(/^[^:]*:(.*)/)[1]; // strip username from key + var timestamp = v.values[0]['data']; + var etag = v.values[0]['metadata']['X-Riak-VTag']; + return [{ - name: key_name, + name: name, timestamp: timestamp, etag: etag }]; diff --git a/spec/directories_spec.rb b/spec/directories_spec.rb index 16124ea..dbe8a3e 100644 --- a/spec/directories_spec.rb +++ b/spec/directories_spec.rb @@ -17,6 +17,7 @@ describe "Directories" do before do put "/jimmy/tasks/foo", "do the laundry" put "/jimmy/tasks/http%3A%2F%2F5apps.com", "prettify design" + put "/jimmy/tasks/%3A/foo%3Abar%40foo.org", "hello world" end it "lists the objects with their version" do @@ -29,10 +30,21 @@ describe "Directories" do content = JSON.parse(last_response.body) content.must_include "http://5apps.com" + content.must_include ":/" content.must_include "foo" content["foo"].must_equal foo.etag.gsub(/"/, "") end + it "doesn't choke on colons in the directory name" do + get "/jimmy/tasks/%3A/" + + last_response.status.must_equal 200 + last_response.content_type.must_equal "application/json" + + content = JSON.parse(last_response.body) + content.must_include "foo:bar@foo.org" + end + it "has a Last-Modifier header set" do get "/jimmy/tasks/" diff --git a/spec/riak_spec.rb b/spec/riak_spec.rb index bc3ea04..65b1ec1 100644 --- a/spec/riak_spec.rb +++ b/spec/riak_spec.rb @@ -462,12 +462,12 @@ describe "App with Riak backend" do context "with escaped key" do before do - put "/jimmy/documents/http%3A%2F%2F5apps.com", "super website" + put "/jimmy/documents/bar%3Abaz/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" + get "/jimmy/documents/bar%3Abaz/http%3A%2F%2F5apps.com" last_response.body.must_equal 'super website' end