Skip to content

Commit a89f19a

Browse files
authored
Merge pull request #22 from Fingertips/manfred-21-slash
Allow slash literal in URL when object contains slash
2 parents 9de837a + 52d71b2 commit a89f19a

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

spec/cases/http_handler_spec.cr

+18
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,24 @@ describe Greitspitz::HttpHandler do
1010
end
1111
end
1212

13+
it "serves an object with a key that includes a slash" do
14+
Spec.with_mocked_object_storage do
15+
session = Spec.create_session
16+
session.get("/avatars/special/8awboFP4bFrbA8dZ/format:jpeg")
17+
session.response_status_code.should eq(200)
18+
session.response_content_type.should eq("image/jpeg")
19+
end
20+
end
21+
22+
it "serves an object with a key that includes a slash" do
23+
Spec.with_mocked_object_storage do
24+
session = Spec.create_session
25+
session.get("/avatars/special%2F8awboFP4bFrbA8dZ/format:jpeg")
26+
session.response_status_code.should eq(200)
27+
session.response_content_type.should eq("image/jpeg")
28+
end
29+
end
30+
1331
it "serves an object from a bucket as a resized AVIF" do
1432
Spec.with_mocked_object_storage do
1533
session = Spec.create_session

spec/spec_helper.cr

+3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ module Spec
4545
WebMock.stub(
4646
:get, "https://storage.example.com/avatars/w8cfGJVMmjzLdgZf?"
4747
).to_return(body_io: file)
48+
WebMock.stub(
49+
:get, "https://storage.example.com/avatars/special/8awboFP4bFrbA8dZ?"
50+
).to_return(body_io: file)
4851
WebMock.stub(
4952
:get, "https://storage.example.com/avatars/1MiD6y6JPh8C4yGT?"
5053
).to_return(status: 404, body_io: IO::Memory.new("<?xml><root></root>"))

src/greitspitz/http_handler.cr

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ module Greitspitz
1111
end
1212

1313
def call(context)
14-
if context.request.path =~ /^\/([^\/]+)\/([^\/]+)\/([^\/]+)$/
15-
handle_request(context, URI.decode($1), URI.decode($2), URI.decode($3))
14+
parts = context.request.path.split("/").map { |part| URI.decode(part) }
15+
if parts.size > 2
16+
handle_request(context, parts[1], parts[2..-2].join("/"), parts[-1])
1617
else
1718
call_next(context)
1819
end

0 commit comments

Comments
 (0)