Skip to content

Commit

Permalink
Merge pull request #1676 from jkowens/fix-1666
Browse files Browse the repository at this point in the history
Preserve query param value if named route param nil
  • Loading branch information
namusyaka committed Feb 13, 2022
2 parents 883cb13 + bb8fca1 commit e9b3d3f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/sinatra/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,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)
@params = @params.merge(params) if params.any?
@params = @params.merge(params) { |k, v1, v2| v2 || v1 } 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 Down
4 changes: 4 additions & 0 deletions test/routing_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,10 @@ class RoutingTest < Minitest::Test
assert ok?
assert_equal "foo=hello;bar=", body

get '/hello?bar=baz'
assert ok?
assert_equal "foo=hello;bar=baz", body

get '/'
assert ok?
assert_equal "foo=;bar=", body
Expand Down

0 comments on commit e9b3d3f

Please sign in to comment.