A platform for community discussion. Free, open, simple.
FIX: Validate tags parameter of TopicQuery (#19830)
Bianca Nenciu0fea826f424f
diff --git a/lib/topic_query.rb b/lib/topic_query.rbindex 5b33a15fbed..cd3ce275080 100644--- a/lib/topic_query.rb+++ b/lib/topic_query.rb@@ -15,10 +15,15 @@ class TopicQuery@validators ||=beginint = lambda { |x| Integer === x || (String === x && x.match?(/^-?[0-9]+$/)) }-zero_up_to_max_int = lambda { |x| int.call(x) && x.to_i.between?(0, PG_MAX_INT) }-- { max_posts: zero_up_to_max_int, min_posts: zero_up_to_max_int, page: zero_up_to_max_int }+ array_or_string = lambda { |x| Array === x || String === x }++ {+ max_posts: zero_up_to_max_int,+ min_posts: zero_up_to_max_int,+ page: zero_up_to_max_int,+ tags: array_or_string,+ }endenddiff --git a/spec/requests/list_controller_spec.rb b/spec/requests/list_controller_spec.rbindex 9307d13353e..547e0573139 100644--- a/spec/requests/list_controller_spec.rb+++ b/spec/requests/list_controller_spec.rb@@ -30,6 +30,9 @@ RSpec.describe ListController doget "/latest?page=1111111111111111111111111111111111111111"expect(response.status).to eq(400)++ get "/latest?tags[1]=hello"+ expect(response.status).to eq(400)endit "returns 200 for legit requests" do@@ -59,6 +62,9 @@ RSpec.describe ListController doget "/latest.json?topic_ids=14583%2C14584"expect(response.status).to eq(200)++ get "/latest?tags[]=hello"+ expect(response.status).to eq(200)end(Discourse.anonymous_filters - [:categories]).each do |filter|