FIX: Default to first page when page params is an array.

This commit is contained in:
Guo Xiang Tan
2016-02-25 11:32:16 +08:00
parent 15ce3b2f49
commit e8de80de98
3 changed files with 13 additions and 7 deletions

View File

@ -49,6 +49,10 @@ class TopicsController < ApplicationController
# existing installs.
return wordpress if params[:best].present?
# work around people somehow sending in arrays,
# arrays are not supported
params[:page] = params[:page].to_i rescue 1
opts = params.slice(:username_filters, :filter, :page, :post_number, :show_deleted)
username_filters = opts[:username_filters]
@ -65,7 +69,7 @@ class TopicsController < ApplicationController
raise Discourse::NotFound
end
page = params[:page].to_i
page = params[:page]
if (page < 0) || ((page - 1) * @topic_view.chunk_size > @topic_view.topic.highest_post_number)
raise Discourse::NotFound
end
@ -529,7 +533,7 @@ class TopicsController < ApplicationController
url << "/#{post_number}" if post_number.to_i > 0
url << ".json" if request.format.json?
page = params[:page].to_i
page = params[:page]
url << "?page=#{page}" if page != 0
redirect_to url, status: 301