Skip to content

Commit 2ced8b6

Browse files
Gregg Van Hovesarahwalther
Gregg Van Hove
authored andcommitted
treat empty path as a directory that needs a slash
Signed-off-by: Sarah McAlear <[email protected]>
1 parent da12367 commit 2ced8b6

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

spec/template_app/lib/server_spec.rb

+5
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,9 @@
55
response = Bookbinder::Server.new.call({'PATH_INFO' => '/foo/path'})
66
expect(response).to eq [301, {"Location"=>"://::0/foo/path/", "Content-Type"=>""}, []]
77
end
8+
9+
it 'adds a / to an empty path' do
10+
response = Bookbinder::Server.new.call({'PATH_INFO' => ''})
11+
expect(response).to eq [301, {"Location"=>"://::0/", "Content-Type"=>""}, []]
12+
end
813
end

template_app/lib/server.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def initialize
2424
end
2525

2626
def call(env)
27-
if env['PATH_INFO'] != '/' && env['PATH_INFO'] =~ MATCH
27+
if env['PATH_INFO'] == '' || env['PATH_INFO'] =~ MATCH
2828
env['PATH_INFO'] += '/'
2929
[301, {'Location' => Rack::Request.new(env).url, 'Content-Type' => ''}, []]
3030
else
@@ -33,8 +33,8 @@ def call(env)
3333
end
3434

3535
private
36-
# regexp to match strings without periods that start and end with a slash
37-
MATCH = %r{^/([^.]*)[^/]$}
36+
# regexp to match strings without periods that start but don't end with a slash
37+
MATCH = %r{^/([^.]+)[^/]$}
3838
end
3939

4040
class NotFound

0 commit comments

Comments
 (0)