Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 50920d6

Browse files
committed
#limit and #offset validate value param
1 parent 7bc4c7b commit 50920d6

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

‎elasticsearch-model/lib/elasticsearch/model/response/pagination.rb‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def offset_value
6666
# Set the "limit" (`size`) value
6767
#
6868
def limit(value)
69+
return if value.to_i <= 0
6970
@results = nil
7071
@records = nil
7172
@response = nil
@@ -79,6 +80,7 @@ def limit(value)
7980
# Set the "offset" (`from`) value
8081
#
8182
def offset(value)
83+
return if value.to_i <= 0
8284
@results = nil
8385
@records = nil
8486
@response = nil

‎elasticsearch-model/test/unit/response_pagination_kaminari_test.rb‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ def self.document_type; 'bar'; end
109109
@response.limit("35")
110110
assert_equal 35, @response.search.definition[:size]
111111
end
112+
113+
should 'ignore invalid string parameters' do
114+
@response.limit(35)
115+
@response.limit("asdf")
116+
assert_equal 35, @response.search.definition[:size]
117+
end
112118
end
113119

114120
context "with the page() and limit() methods" do
@@ -161,6 +167,12 @@ def self.document_type; 'bar'; end
161167
@response.offset("35")
162168
assert_equal 35, @response.search.definition[:from]
163169
end
170+
171+
should 'ignore invalid string parameters' do
172+
@response.offset(35)
173+
@response.offset("asdf")
174+
assert_equal 35, @response.search.definition[:from]
175+
end
164176
end
165177

166178
context "total" do

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /