Skip to content

Commit 4f7e0b0

Browse files
committed
expanding and real paths (esp. with FS layout) should handle nils
1 parent f681243 commit 4f7e0b0

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

src/main/ruby/jruby/rack/app_layout.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def public_uri
7676
end
7777

7878
def expand_path(path)
79+
return nil if path.nil?
7980
if path.start_with?(app_uri) # gem_path = '/WEB-INF/gems'
8081
path = path.dup; path[0, app_uri.size] = app_path; path # '[app_path]/gems'
8182
path
@@ -90,7 +91,7 @@ def expand_path(path)
9091

9192
RailsWebInfLayout = WebInfLayout
9293

93-
# #deprecated will be removed (with Merb support)
94+
# @deprecated will be removed (with Merb support)
9495
class MerbWebInfLayout < WebInfLayout
9596

9697
def app_uri
@@ -120,7 +121,7 @@ def public_uri
120121
end
121122

122123
def real_path(path)
123-
expand_path(super)
124+
path.nil? ? nil : expand_path(super)
124125
end
125126

126127
def expand_path(path)

src/spec/ruby/jruby/rack/app_layout_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,26 @@
6565
expect( layout.gem_path ).to eq "/var/local/app/gem"
6666
end
6767

68+
it "expands path app_uri relatively" do
69+
layout.instance_variable_set :@app_uri, "/WEB-INF/"
70+
layout.instance_variable_set :@app_path, "/home/deploy/current/WEB-INF/"
71+
72+
expect( layout.expand_path("app/gem") ).to eq "/home/deploy/current/WEB-INF/app/gem"
73+
end
74+
75+
it "expands paths starting with app path" do
76+
layout.instance_variable_set :@app_uri, "/WEB-INF"
77+
layout.instance_variable_set :@app_path, "/home/deploy/current/WEB-INF"
78+
79+
expect( layout.expand_path("/WEB-INF/app/gem") ).to eq "/home/deploy/current/WEB-INF/app/gem"
80+
end
81+
82+
it "expands nil path as nil" do
83+
layout.instance_variable_set :@app_uri, "/WEB-INF/"
84+
85+
expect( layout.expand_path(nil) ).to eq nil
86+
end
87+
6888
end
6989

7090
shared_examples "FileSystemLayout" do
@@ -114,6 +134,14 @@
114134
expect( layout.public_path ).to eq "/home/public/root"
115135
end
116136

137+
it "expands nil path as nil" do
138+
expect( layout.expand_path(nil) ).to eq nil
139+
end
140+
141+
it "handles nil real path as nil" do
142+
expect( layout.real_path(nil) ).to eq nil
143+
end
144+
117145
end
118146

119147
describe JRuby::Rack::FileSystemLayout do

0 commit comments

Comments
 (0)