wiki pages: fix 404s for page titles containing dots.
Bug: links like these returned 404s: * https://danbooru.donmai.us/wiki_pages/... * https://danbooru.donmai.us/wiki_pages/.hack// * https://danbooru.donmai.us/wiki_pages/ssss.gridman Cause: by default, Rails uses dots in route segments to separate the id from the format. For example, in /wiki_pages/ssss.gridman, the id is parsed as "ssss" and the format is "gridman" (as if "gridman" were a format like "json" or "xml"). We work around this by specifying the regex for the id param manually. The trick here is to use a non-greedy match-all combined with a positive lookahead to detect the extension but not include it in the match.
This commit is contained in:
@@ -295,14 +295,10 @@ Rails.application.routes.draw do
|
||||
resource :user_upgrade, :only => [:new, :create, :show]
|
||||
resources :user_feedbacks
|
||||
resources :user_name_change_requests, only: [:new, :create, :show, :index]
|
||||
resources :wiki_pages do
|
||||
member do
|
||||
put :revert
|
||||
end
|
||||
collection do
|
||||
get :search
|
||||
get :show_or_new
|
||||
end
|
||||
resources :wiki_pages, id: /.+?(?=\.json|\.xml|\.html)|.+/ do
|
||||
put :revert, on: :member
|
||||
get :search, on: :collection
|
||||
get :show_or_new, on: :collection
|
||||
end
|
||||
resources :wiki_page_versions, :only => [:index, :show, :diff] do
|
||||
collection do
|
||||
|
||||
@@ -86,6 +86,19 @@ class WikiPagesControllerTest < ActionDispatch::IntegrationTest
|
||||
get wiki_page_path(@wiki_page.id)
|
||||
assert_redirected_to wiki_page_path(@wiki_page.title)
|
||||
end
|
||||
|
||||
should "work for a title containing dots" do
|
||||
as(@user) { create(:wiki_page, title: "...") }
|
||||
|
||||
get wiki_page_path("...")
|
||||
assert_response :success
|
||||
|
||||
get wiki_page_path("....json")
|
||||
assert_response :success
|
||||
|
||||
get wiki_page_path("....xml")
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
context "show_or_new action" do
|
||||
|
||||
Reference in New Issue
Block a user