FIX: Validate tags parameter of TopicQuery (#19830)

Recently, we have seen some errors related to invalid tags value being
passed to TopicQuery.
This commit is contained in:
Bianca Nenciu
2023-01-16 19:20:19 +02:00
committed by GitHub
parent c3070288ea
commit 0fea826f42
2 changed files with 13 additions and 2 deletions

View File

@ -15,10 +15,15 @@ class TopicQuery
@validators ||=
begin
int = 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) }
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 }
{
max_posts: zero_up_to_max_int,
min_posts: zero_up_to_max_int,
page: zero_up_to_max_int,
tags: array_or_string,
}
end
end