Skip to content

Commit 555d558

Browse files
authored
Prevent changing host through params (#1391)
1 parent cb712fd commit 555d558

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/ransack/helpers/form_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def name
129129
end
130130

131131
def url_options
132-
@params.merge(
132+
@params.except(:host).merge(
133133
@options.except(:class, :data, :host).merge(
134134
@search.context.search_key => search_and_sort_params))
135135
end

spec/ransack/helpers/form_helper_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,14 @@ module Helpers
808808
it { should_not match /href=".*foo/ }
809809
end
810810

811+
describe "#sort_link ignores host in params" do
812+
before { @controller.view_context.params[:host] = 'other_domain' }
813+
subject { @controller.view_context.sort_link(Person.ransack, :name, controller: 'people') }
814+
815+
it { should match /href="\/people\?q/ }
816+
it { should_not match /href=".*other_domain/ }
817+
end
818+
811819
describe '#search_form_for with default format' do
812820
subject { @controller.view_context
813821
.search_form_for(Person.ransack) {} }

0 commit comments

Comments
 (0)