Don't choke on colons in directory names (fixes #39)
This commit is contained in:
parent
3dd79e28d3
commit
9e6cc6178d
@ -270,14 +270,19 @@ module RemoteStorage
|
|||||||
|
|
||||||
map_query = <<-EOH
|
map_query = <<-EOH
|
||||||
function(v){
|
function(v){
|
||||||
keys = v.key.split(':');
|
var metadata = v.values[0]['metadata'];
|
||||||
keys.splice(0, 2);
|
var dir_name = metadata['index']['directory_bin'];
|
||||||
key_name = keys.join(':');
|
if (dir_name === '/') {
|
||||||
last_modified_date = v.values[0]['metadata']['X-Riak-Last-Modified'];
|
dir_name = '';
|
||||||
timestamp = v.values[0]['metadata']['X-Riak-Meta']['X-Riak-Meta-Timestamp'];
|
}
|
||||||
etag = v.values[0]['metadata']['X-Riak-VTag'];
|
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 [{
|
return [{
|
||||||
name: key_name,
|
name: name,
|
||||||
last_modified: last_modified_date,
|
last_modified: last_modified_date,
|
||||||
timestamp: timestamp,
|
timestamp: timestamp,
|
||||||
etag: etag
|
etag: etag
|
||||||
@ -294,12 +299,12 @@ module RemoteStorage
|
|||||||
|
|
||||||
map_query = <<-EOH
|
map_query = <<-EOH
|
||||||
function(v){
|
function(v){
|
||||||
keys = v.key.split(':');
|
var name = v.key.match(/^[^:]*:(.*)/)[1]; // strip username from key
|
||||||
key_name = keys[keys.length-1];
|
var timestamp = v.values[0]['data'];
|
||||||
timestamp = v.values[0]['data'];
|
var etag = v.values[0]['metadata']['X-Riak-VTag'];
|
||||||
etag = v.values[0]['metadata']['X-Riak-VTag'];
|
|
||||||
return [{
|
return [{
|
||||||
name: key_name,
|
name: name,
|
||||||
timestamp: timestamp,
|
timestamp: timestamp,
|
||||||
etag: etag
|
etag: etag
|
||||||
}];
|
}];
|
||||||
|
@ -17,6 +17,7 @@ describe "Directories" do
|
|||||||
before do
|
before do
|
||||||
put "/jimmy/tasks/foo", "do the laundry"
|
put "/jimmy/tasks/foo", "do the laundry"
|
||||||
put "/jimmy/tasks/http%3A%2F%2F5apps.com", "prettify design"
|
put "/jimmy/tasks/http%3A%2F%2F5apps.com", "prettify design"
|
||||||
|
put "/jimmy/tasks/%3A/foo%3Abar%40foo.org", "hello world"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "lists the objects with their version" do
|
it "lists the objects with their version" do
|
||||||
@ -29,10 +30,21 @@ describe "Directories" do
|
|||||||
|
|
||||||
content = JSON.parse(last_response.body)
|
content = JSON.parse(last_response.body)
|
||||||
content.must_include "http://5apps.com"
|
content.must_include "http://5apps.com"
|
||||||
|
content.must_include ":/"
|
||||||
content.must_include "foo"
|
content.must_include "foo"
|
||||||
content["foo"].must_equal foo.etag.gsub(/"/, "")
|
content["foo"].must_equal foo.etag.gsub(/"/, "")
|
||||||
end
|
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
|
it "has a Last-Modifier header set" do
|
||||||
get "/jimmy/tasks/"
|
get "/jimmy/tasks/"
|
||||||
|
|
||||||
|
@ -462,12 +462,12 @@ describe "App with Riak backend" do
|
|||||||
|
|
||||||
context "with escaped key" do
|
context "with escaped key" do
|
||||||
before 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
|
end
|
||||||
|
|
||||||
it "delivers the data correctly" do
|
it "delivers the data correctly" do
|
||||||
header "Authorization", "Bearer 123"
|
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'
|
last_response.body.must_equal 'super website'
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user