summaryrefslogtreecommitdiff
path: root/lib/api/pagination_params.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-08-04 21:08:44 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-08-04 21:08:44 +0000
commit1793989cccd91d457aef6434e4929f318ca54b0a (patch)
treed014467bc84776ba33dbe74920b79985131ac157 /lib/api/pagination_params.rb
parent2857ba3ce5c9272b99ab2cc4a3d2564504d7ed0e (diff)
downloadgitlab-ce-1793989cccd91d457aef6434e4929f318ca54b0a.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/api/pagination_params.rb')
-rw-r--r--lib/api/pagination_params.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/api/pagination_params.rb b/lib/api/pagination_params.rb
index 85ac50d5bec..bdb69d0ba44 100644
--- a/lib/api/pagination_params.rb
+++ b/lib/api/pagination_params.rb
@@ -20,6 +20,26 @@ module API
optional :page, type: Integer, default: 1, desc: 'Current page number'
optional :per_page, type: Integer, default: 20, desc: 'Number of items per page', except_values: [0]
end
+
+ def verify_pagination_params!
+ return if Feature.disabled?(:only_positive_pagination_values)
+
+ page = begin
+ Integer(params[:page])
+ rescue ArgumentError, TypeError
+ nil
+ end
+
+ return render_structured_api_error!({ error: 'page does not have a valid value' }, 400) if page&.< 1
+
+ per_page = begin
+ Integer(params[:per_page])
+ rescue ArgumentError, TypeError
+ nil
+ end
+
+ return render_structured_api_error!({ error: 'per_page does not have a valid value' }, 400) if per_page&.< 1
+ end
end
end
end