Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve query param value if named route param nil #1676

Merged
merged 1 commit into from
Feb 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/sinatra/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,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