Don't choke on colons in directory names (fixes #39)

This commit is contained in:
Garret Alfert 2014-02-24 17:43:43 +01:00
parent 3dd79e28d3
commit 9e6cc6178d
3 changed files with 31 additions and 14 deletions

View File

@ -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
}];

View File

@ -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/"

View File

@ -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