A platform for community discussion. Free, open, simple.
DEV: Add configurable limit for page param in TopicQuery (#34728)
Penar Musaraj6f3a52c30de1
diff --git a/config/site_settings.yml b/config/site_settings.ymlindex 031f9f1d60f..c1b41f54e1e 100644--- a/config/site_settings.yml+++ b/config/site_settings.yml@@ -3641,11 +3641,17 @@ uncategorized:overridden_robots_txt:default: ""hidden: true+show_category_definitions_in_topic_lists:default: falsehidden: trueclient: true+ max_topic_query_page_param:+ default: 2000+ min: 100+ hidden: true+create_revision_on_bulk_topic_moves:default: truearea: "posts_and_topics"diff --git a/lib/topic_query.rb b/lib/topic_query.rbindex 0010c708c5a..d9ec5384169 100644--- a/lib/topic_query.rb+++ b/lib/topic_query.rb@@ -16,13 +16,15 @@ class TopicQuerybeginint = lambda { |x| Integer === x || (String === x && x.match?(/\A-?[0-9]+\z/)) }zero_up_to_max_int = lambda { |x| int.call(x) && x.to_i.between?(0, PG_MAX_INT) }+ zero_up_to_max_page =+ lambda { |x| int.call(x) && x.to_i.between?(0, SiteSetting.max_topic_query_page_param) }one_up_to_one_hundred = lambda { |x| int.call(x) && x.to_i.between?(1, 100) }array_or_string = lambda { |x| Array === x || String === x }string = lambda { |x| String === x }true_or_false = lambda { |x| x == true || x == false || x == "true" || x == "false" }{- page: zero_up_to_max_int,+ page: zero_up_to_max_page,per_page: one_up_to_one_hundred,before: zero_up_to_max_int,bumped_before: zero_up_to_max_int,diff --git a/spec/lib/topic_query_spec.rb b/spec/lib/topic_query_spec.rbindex 04fab275eeb..11d5ecbc8ff 100644--- a/spec/lib/topic_query_spec.rb+++ b/spec/lib/topic_query_spec.rb@@ -105,6 +105,20 @@ RSpec.describe TopicQuery doexpect(TopicQuery.validate?(:per_page, "10")).to eq(true)endend++ describe "page" do+ it "respects SiteSetting.max_topic_query_page_param" do+ SiteSetting.max_topic_query_page_param = 100++ expect(TopicQuery.validate?(:page, -1)).to eq(false)+ expect(TopicQuery.validate?(:page, 101)).to eq(false)++ expect(TopicQuery.validate?(:page, 0)).to eq(true)+ expect(TopicQuery.validate?(:page, 1)).to eq(true)+ expect(TopicQuery.validate?(:page, 100)).to eq(true)+ expect(TopicQuery.validate?(:page, "10")).to eq(true)+ end+ endenddescribe "#list_topics_by" dodiff --git a/spec/requests/list_controller_spec.rb b/spec/requests/list_controller_spec.rbindex 56336da82f7..98427ed2008 100644--- a/spec/requests/list_controller_spec.rb+++ b/spec/requests/list_controller_spec.rb@@ -158,7 +158,7 @@ RSpec.describe ListController doget "/latest?page=1"expect(response.status).to eq(200)- get "/latest.json?page=2147483647"+ get "/latest.json?page=1999"expect(response.status).to eq(200)get "/latest?search="