Skip to content

Commit ec63b40

Browse files
authored
Merge pull request #2 from TaopaiC/patch/double_slash
FIX URI path handling to remove double slashes
2 parents 6a20a5d + 327f828 commit ec63b40

2 files changed

Lines changed: 52 additions & 0 deletions

File tree

lib/vault/client.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,15 @@ def request(verb, path, data = {}, headers = {})
305305
end
306306
end
307307

308+
# Removes double slashes from a path.
309+
#
310+
# @param [String]
311+
#
312+
# @return [String]
313+
def remove_double_slash(path)
314+
path.b.gsub(%r{//+}, '/')
315+
end
316+
308317
# Construct a URL from the given verb and path. If the request is a GET or
309318
# DELETE request, the params are assumed to be query params are are
310319
# converted as such using {Client#to_query_string}.
@@ -333,6 +342,8 @@ def build_uri(verb, path, params = {})
333342
# Don't merge absolute URLs
334343
uri = URI.parse(File.join(address, path)) unless uri.absolute?
335344

345+
uri.path = remove_double_slash(uri.path)
346+
336347
# Return the URI object
337348
uri
338349
end

spec/integration/api/logical_spec.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,20 @@ module Vault
5858
expect(secret).to be
5959
expect(secret.data).to eq(foo: "bar")
6060
end
61+
62+
it "allows double slash" do
63+
subject.write("secret/test-read", foo: "bar")
64+
secret = subject.read("secret///test-read")
65+
expect(secret).to be
66+
expect(secret.data).to eq(foo: "bar")
67+
end
68+
69+
it "allows double slash and special characters" do
70+
subject.write("secret/b:@c%n-read-slash", foo: "bar")
71+
secret = subject.read("secret///b:@c%n-read-slash")
72+
expect(secret).to be
73+
expect(secret.data).to eq(foo: "bar")
74+
end
6175
end
6276

6377
describe "#write" do
@@ -84,6 +98,21 @@ module Vault
8498
expect(secret.data).to eq(bacon: true)
8599
end
86100

101+
it "allows double slash" do
102+
subject.write("secret///test-write", zip: "zap")
103+
result = subject.read("secret/test-write")
104+
expect(result).to be
105+
expect(result.data).to eq(zip: "zap")
106+
end
107+
108+
it "allows double slash and special characters" do
109+
subject.write("secret///b:@c%n-write", foo: "bar")
110+
subject.write("secret///b:@c%n-write", bacon: true)
111+
secret = subject.read("secret/b:@c%n-write")
112+
expect(secret).to be
113+
expect(secret.data).to eq(bacon: true)
114+
end
115+
87116
it "respects spaces properly" do
88117
key = 'secret/sub/"Test Group"'
89118
subject.write(key, foo: "bar")
@@ -107,6 +136,18 @@ module Vault
107136
expect(subject.read("secret/b:@c%n-delete")).to be(nil)
108137
end
109138

139+
it "allows double slash" do
140+
subject.write("secret/delete", foo: "bar")
141+
expect(subject.delete("secret///delete")).to be(true)
142+
expect(subject.read("secret/delete")).to be(nil)
143+
end
144+
145+
it "allows double slash and special characters" do
146+
subject.write("secret/b:@c%n-delete-slash", foo: "bar")
147+
expect(subject.delete("secret///b:@c%n-delete-slash")).to be(true)
148+
expect(subject.read("secret/b:@c%n-delete-slash")).to be(nil)
149+
end
150+
110151
it "does not error if the secret does not exist" do
111152
expect {
112153
subject.delete("secret/delete")

0 commit comments

Comments
 (0)