From 37ad6f5a712392db3a704c3cb6352224c9473405 Mon Sep 17 00:00:00 2001 From: evazion Date: Tue, 8 Feb 2022 00:02:18 -0600 Subject: [PATCH] Fix non-existent .js requests raising DoubleRenderError. Fix requests for non-existent .js pages, for example https://danbooru.donmai.us/oaisfj.js, raising AbstractController::DoubleRenderError when trying to render the 404 response. --- app/controllers/static_controller.rb | 1 + app/views/static/not_found.js | 0 test/functional/static_controller_test.rb | 7 +++++++ 3 files changed, 8 insertions(+) create mode 100644 app/views/static/not_found.js diff --git a/app/controllers/static_controller.rb b/app/controllers/static_controller.rb index 8061545f7..422387699 100644 --- a/app/controllers/static_controller.rb +++ b/app/controllers/static_controller.rb @@ -2,6 +2,7 @@ class StaticController < ApplicationController respond_to :html, :json, :xml + skip_forgery_protection only: :not_found, if: -> { request.format.js? } def privacy_policy end diff --git a/app/views/static/not_found.js b/app/views/static/not_found.js new file mode 100644 index 000000000..e69de29bb diff --git a/test/functional/static_controller_test.rb b/test/functional/static_controller_test.rb index 77f1332a4..a84fc056b 100644 --- a/test/functional/static_controller_test.rb +++ b/test/functional/static_controller_test.rb @@ -71,6 +71,13 @@ class StaticControllerTest < ActionDispatch::IntegrationTest assert_equal("Page not found", response.parsed_body.xpath("result/message").text) end + should "return a JS response for a 404'd .js request" do + get "/qwoiqogieqg.js" + + assert_response 404 + assert_equal("", response.body) + end + should "render the 404 page when page_not_found_pool_id is configured" do as(create(:user)) do @post = create(:post, tag_string: "artist:bkub")