Fix #4591: Wiki pages with filename-like name are broken by default.
Fix wiki pages like this returning 406 errors: * https://danbooru.donmai.us/wiki_pages/rnd.jpg Caused by Rails parsing the .jpg part as a file extension and trying to return a JPEG in response. This happens deep in Rails' MIME negotiation code, so it's hard to override. The fix is to pass `format: false` in the route to disable all special handling of file extensions by Rails, and then handle it ourselves in the controller. Ugly. This only affected two tags: `rnd.jpg` and `haru.jpg`.
This commit is contained in:
@@ -30,6 +30,15 @@ class WikiPagesController < ApplicationController
|
||||
end
|
||||
|
||||
def show
|
||||
if params[:format].present?
|
||||
request.format = params[:format]
|
||||
elsif params[:id].ends_with?(".html", ".json", ".xml")
|
||||
request.format = params[:id].split(".").last
|
||||
params[:id].delete_suffix!(".#{request.format.symbol}")
|
||||
else
|
||||
request.format = "html"
|
||||
end
|
||||
|
||||
@wiki_page, found_by = WikiPage.find_by_id_or_title(params[:id])
|
||||
|
||||
if request.format.html? && @wiki_page.blank? && found_by == :title
|
||||
|
||||
Reference in New Issue
Block a user