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:
evazion
2022-01-19 21:44:40 -06:00
parent d6b1302e0b
commit 0db20e0cab
3 changed files with 39 additions and 1 deletions

View File

@@ -122,6 +122,35 @@ class WikiPagesControllerTest < ActionDispatch::IntegrationTest
assert_response :success
end
should "work for a title containing a file extension" do
as(@user) { create(:wiki_page, title: "rnd.jpg") }
as(@user) { create(:wiki_page, title: "touhou") }
get wiki_page_path("rnd.jpg")
assert_response :success
assert_equal("text/html", response.media_type)
get wiki_page_path("rnd.jpg.json")
assert_response :success
assert_equal("application/json", response.media_type)
get wiki_page_path("rnd.jpg.xml")
assert_response :success
assert_equal("application/xml", response.media_type)
get wiki_page_path("rnd.jpg.html")
assert_response :success
assert_equal("text/html", response.media_type)
get wiki_page_path("rnd.jpg", format: "json")
assert_response :success
assert_equal("application/json", response.media_type)
get wiki_page_path("touhou.json")
assert_response :success
assert_equal("application/json", response.media_type)
end
should "mark banned artists as noindex" do
@artist = create(:artist, name: @wiki_page.title, is_banned: true)
get wiki_page_path(@wiki_page.title)