Comments (4)
Can you check if #51247 works for you?
from rails.
Reproducable test case
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "rails"
# If you want to test against edge Rails replace the previous line with this:
# gem "rails", github: "rails/rails", branch: "main"
end
require "action_controller/railtie"
class TestApp < Rails::Application
config.root = __dir__
config.hosts << "example.org"
config.secret_key_base = "secret_key_base"
config.logger = Logger.new($stdout)
Rails.logger = config.logger
routes.draw do
get "/about", to: "test#about"
match "/404", to: "test#not_found", via: :all
end
config.exceptions_app = self.routes
end
class TestController < ActionController::Base
include Rails.application.routes.url_helpers
def about
render "/about"
end
def not_found
render json: { error: "some error message" }, status: :not_found
end
end
require "minitest/autorun"
require "rack/test"
class BugTest < Minitest::Test
include Rack::Test::Methods
def test_returns_success
post "/about", nil, { "CONTENT_TYPE" => "invalid" }
refute_equal(500, last_response.status)
end
private
def app
Rails.application
end
end
from rails.
Can you check if #51247 works for you?
It worked!
from rails.
Thank you for writing the reproducable test case.
I also have to fix request.formats
to ActionDispatch::Request.new(request.env.clone).formats
,
because following lines add the RACK_REQUEST_FORM_ERROR
header when the request.formats
method is called.
https://github.com/rack/rack/blob/a4bc5e0f41c750135969ceece8772ab112dc8f17/lib/rack/request.rb#L536-L538
I tried to write a PR, but it seems it takes time to setup development environment.
diff --git a/actionpack/lib/action_dispatch/middleware/show_exceptions.rb b/actionpack/lib/action_dispatch/middleware/show_exceptions.rb
index 5f7368de56..deb07e6018 100644
--- a/actionpack/lib/action_dispatch/middleware/show_exceptions.rb
+++ b/actionpack/lib/action_dispatch/middleware/show_exceptions.rb
@@ -67,9 +67,10 @@ def render_exception(request, wrapper)
def fallback_to_html_format_if_invalid_mime_type(request)
# If the MIME type for the request is invalid then the @exceptions_app may not
# be able to handle it. To make it easier to handle, we switch to HTML.
- request.formats
+ ActionDispatch::Request.new(request.env.clone).formats
rescue ActionDispatch::Http::MimeNegotiation::InvalidType
request.set_header "HTTP_ACCEPT", "text/html"
+ request.set_header "CONTENT_TYPE", "application/x-www-form-urlencoded"
end
def pass_response(status)
****/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/rack-3.0.9.1/lib/rack/request.rb:503:in `POST'
****/Documents/repositories/rails/actionpack/lib/action_dispatch/http/request.rb:407:in `block (2 levels) in POST'
****/Documents/repositories/rails/actionpack/lib/action_dispatch/http/parameters.rb:90:in `parse_formatted_parameters'
****/Documents/repositories/rails/actionpack/lib/action_dispatch/http/request.rb:406:in `block in POST'
****/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/rack-3.0.9.1/lib/rack/request.rb:107:in `fetch'
****/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/rack-3.0.9.1/lib/rack/request.rb:107:in `fetch_header'
****/Documents/repositories/rails/actionpack/lib/action_dispatch/http/request.rb:405:in `POST'
****/Documents/repositories/rails/actionpack/lib/action_dispatch/http/parameters.rb:57:in `parameters'
****/Documents/repositories/rails/actionpack/lib/action_dispatch/http/mime_negotiation.rb:165:in `params_readable?'
****/Documents/repositories/rails/actionpack/lib/action_dispatch/http/mime_negotiation.rb:69:in `block in formats'
****/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/rack-3.0.9.1/lib/rack/request.rb:107:in `fetch'
****/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/rack-3.0.9.1/lib/rack/request.rb:107:in `fetch_header'
****/Documents/repositories/rails/actionpack/lib/action_dispatch/http/mime_negotiation.rb:68:in `formats'
****/Documents/repositories/rails/actionpack/lib/action_dispatch/middleware/show_exceptions.rb:70:in `fallback_to_html_format_if_invalid_mime_type'
****/Documents/repositories/rails/actionpack/lib/action_dispatch/middleware/show_exceptions.rb:52:in `render_exception'
from rails.
Related Issues (20)
- Order of operations for saving nested associations has changed in Rails v7.2 with automatically_invert_plural_associations enabled HOT 7
- rescue_from not working with subscribed method on ActionCable channel HOT 2
- Production rails server does not boot if skipping action cable in Rails 8.0.0.alpha HOT 2
- Generate Migration - Rename Table HOT 6
- Rails 7.1 Transactional tests, threaded code and schema caching can cause deadlocks HOT 1
- /Users/amol/.rvm/gems/ruby-2.5.1/gems/activerecord-5.0.2/lib/active_record/connection_adapters/mysql2_adapter.rb:68: [BUG] Segmentation fault at 0x94000f78d65f0300 ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin23] HOT 1
- Support enum in tableless model HOT 4
- `ActiveStorage::Attachment` - Unhandled case where `named_variants` can be `nil`
- `ActiveSupport::BroadcastLogger` with `ActiveSupport::TaggedLogging` throws `no implicit conversion of String into Integer (TypeError)` HOT 3
- Guides: Explain reset_column_information in Chapter "Migrations and Seed Data"
- One of `ApplicationTests::ConfigurationTest` fails with sqlite3 gem that bundles sqlite v3.46.0 HOT 3
- Add a datetime_local method on Time and DateTime classes - typical rails convenience HOT 1
- Deferred route drawing causes problems with some tests
- Incorrect documentation for authenticate_or_request_with_http_token HOT 1
- Regression in URL generation in Rails 7.1 HOT 13
- ActionCable tests fail when encrypted cookie is set with options
- Turbo depends on ActiveJob::Base but no error when I start a project with `rails new . --skip-active-job` HOT 1
- ActionPack 7.1.3.3 Selenium DriverFinder.path(options, service_class) deprecation is NOT fixed HOT 1
- warning: the block passed to 'Arel::Collectors::Bind#add_bind' defined at /rails/activerecord/lib/arel/collectors/bind.rb:16 may be ignored
- Association klass with same demodularized name raises error when demodularized class is undefined
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rails.