Skip to content

Commit 544f3b5

Browse files
committed
Fix multi-method routes to append '(.:format)' only once
Because the same path string is used for each loop when the routes are being built, appending the string using `<<` modifies the original, causing multiple '(.:format)' strings to be appended. This fixes the behavior, resulting in the proper path output. Signed-off-by: Evan Owen <[email protected]>
1 parent f8d280b commit 544f3b5

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

lib/grape/endpoint.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ def prepare_path(path)
8585
parts << ':version' if settings[:version] && settings[:version_options][:using] == :path
8686
parts << namespace.to_s if namespace
8787
parts << path.to_s if path && '/' != path
88-
parts.last << '(.:format)'
89-
Rack::Mount::Utils.normalize_path(parts.join('/'))
88+
Rack::Mount::Utils.normalize_path(parts.join('/') + '(.:format)')
9089
end
9190

9291
def namespace

spec/grape/api_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,10 @@ def app; subject end
230230
"hiya"
231231
end
232232

233+
subject.endpoints.first.routes.each do |route|
234+
route.route_path.should eql '/abc(.:format)'
235+
end
236+
233237
get '/abc'
234238
last_response.body.should eql 'hiya'
235239
post '/abc'

0 commit comments

Comments
 (0)