Skip to content

Commit

Permalink
Remove only routing parameters from @params hash
Browse files Browse the repository at this point in the history
Changes to the @params hash were being lost if routing params were
supplied because the whole hash was being reset after processing the
route.
  • Loading branch information
jkowens committed Oct 26, 2019
1 parent 6ee7fc1 commit 1f8f41d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/sinatra/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,7 @@ def process_route(pattern, conditions, block = nil, values = [])

params.delete("ignore") # TODO: better params handling, maybe turn it into "smart" object or detect changes
force_encoding(params)
original, @params = @params, @params.merge(params) if params.any?
@params = @params.merge(params) if params.any?

regexp_exists = pattern.is_a?(Mustermann::Regular) || (pattern.respond_to?(:patterns) && pattern.patterns.any? {|subpattern| subpattern.is_a?(Mustermann::Regular)} )
if regexp_exists
Expand All @@ -1038,7 +1038,8 @@ def process_route(pattern, conditions, block = nil, values = [])
@env['sinatra.error.params'] = @params
raise
ensure
@params = original if original
params ||= {}
@params.delete_if { |k, _| params.key?(k) } unless @env['sinatra.error.params'] || params.empty?
end

# No matching route was found or all routes passed. The default
Expand Down

0 comments on commit 1f8f41d

Please sign in to comment.