Fix #4973: Wiki pages json index returns 404.
Fix regression introduced in 0db20e0ca. Setting `format: false` on the
wiki pages resource disabled format negotiation on all wiki page routes,
not just the show page, which meant /wiki_pages.json no longer worked.
The fix to monkey patch the internal Rails method that parses the file
extension from the URL, and have it ignore everything but the .html,
.json, .js, and .xml extensions. This is really hacky and may break in
future Rails releases.
This commit is contained in:
@@ -63,6 +63,23 @@ class String
|
||||
include Danbooru::Extensions::String
|
||||
end
|
||||
|
||||
module MimeNegotationExtension
|
||||
# Ignore all file extensions except for .html, .js, .json, and .xml when
|
||||
# parsing the file extension from the URL. Needed for wiki pages (e.g.
|
||||
# /wiki_pages/rnd.jpg).
|
||||
private def format_from_path_extension
|
||||
mime = super
|
||||
|
||||
if mime&.symbol.in?(%i[html js json xml])
|
||||
mime
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
ActionDispatch::Http::MimeNegotiation.prepend(MimeNegotationExtension)
|
||||
|
||||
# Make Symbol#to_s return a frozen string. This reduces allocations, but may be
|
||||
# incompatible with some libraries.
|
||||
#
|
||||
|
||||
@@ -280,7 +280,7 @@ Rails.application.routes.draw do
|
||||
resources :webhooks do
|
||||
post :receive, on: :collection
|
||||
end
|
||||
resources :wiki_pages, id: /.+/, format: false do
|
||||
resources :wiki_pages, id: /.+?(?=\.json|\.xml|\.html)|.+/ do
|
||||
put :revert, on: :member
|
||||
get :search, on: :collection
|
||||
get :show_or_new, on: :collection
|
||||
|
||||
Reference in New Issue
Block a user