From 06f82a7d72f79f1419b4ea8c1d264476dd794d87 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 15 Aug 2018 11:31:42 +1000 Subject: [PATCH] correct exception handling, always do to_i in array --- lib/topic_query.rb | 4 ++-- spec/requests/list_controller_spec.rb | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/topic_query.rb b/lib/topic_query.rb index 01952bd5991..6fdf2280d4f 100644 --- a/lib/topic_query.rb +++ b/lib/topic_query.rb @@ -18,7 +18,7 @@ class TopicQuery end array_int = lambda do |x| - Array === x && x.length > 0 && x.all? { |i| Integer === i } + Array === x && x.length > 0 && x.all? { |i| Integer === i || i.match?(/^-?[0-9]+$/) } end { @@ -656,7 +656,7 @@ class TopicQuery result = apply_shared_drafts(result, category_id, options) if options[:exclude_category_ids] && options[:exclude_category_ids].is_a?(Array) && options[:exclude_category_ids].size > 0 - result = result.where("categories.id NOT IN (?)", options[:exclude_category_ids]).references(:categories) + result = result.where("categories.id NOT IN (?)", options[:exclude_category_ids].map(&:to_i)).references(:categories) end # Don't include the category topics if excluded diff --git a/spec/requests/list_controller_spec.rb b/spec/requests/list_controller_spec.rb index a228061dd87..76c216cd86e 100644 --- a/spec/requests/list_controller_spec.rb +++ b/spec/requests/list_controller_spec.rb @@ -30,6 +30,11 @@ RSpec.describe ListController do expect(response.status).to eq(400) end + it "returns 200 for legit requests" do + get "/latest.json?exclude_category_ids%5B%5D=69&exclude_category_ids%5B%5D=70&no_definitions=true&no_subcategories=false&page=1&_=1534296100767" + expect(response.status).to eq(200) + end + it "doesn't throw an error with page params as an array" do get "/#{Discourse.anonymous_filters[1]}", params: { page: ['7'] } expect(response.status).to eq(200)