Commit Graph

15915 Commits

Author SHA1 Message Date
Petrik de Heus a84ef12221
Merge pull request #48383 from p8/fix/link-to-cookies
Fix link to ActionController::Cookies#cookies [ci-skip]
2023-06-02 18:13:54 +02:00
Petrik f492d51795 Fix link to ActionController::Cookies#cookies
The `cookies` method was not defined on ActionController::Base making the
permalink to the method not work.
Changing it to ActionController::Cookies make the reference a link.
2023-06-02 16:53:38 +02:00
Marek de Heus 39156c8812
Update actionpack/lib/action_controller/metal.rb
Co-authored-by: Petrik de Heus <petrik@deheus.net>
2023-06-02 15:10:49 +02:00
Marek de Heus 0da0fc8979 Add missing docs for request.session 2023-06-02 15:04:21 +02:00
Jeremy Beker c34d1f0a68
Base case with our checks last in conditional 2023-05-30 20:49:45 +00:00
Jeremy Beker d00843aa13
Test case with our checks first in conditional 2023-05-30 20:49:44 +00:00
Jeremy Beker f1889f139d
Indentation correction via rubocop. 2023-05-30 20:49:41 +00:00
Jason Meller 1904a3031a
Re-order conditional for maybe better perf 2023-05-30 20:48:11 +00:00
Jason Meller afb847f1b7
Fix spelling error 2023-05-30 20:48:08 +00:00
Jason Meller 1bca0dc586
PR feedback 2023-05-30 20:47:52 +00:00
Jason Meller 4370293a68
Implement PR suggestions 2023-05-30 20:47:30 +00:00
Jason Meller e388ebe0f2
Attempt to fix rubocop warnings 2023-05-30 20:47:29 +00:00
Jason Meller a78d3e3207
Enable `bind_params` option in url_for helper
The url_for helper now supports a new option called `bind_params`.
This is very useful in situations where you only want to add a required
param that is part of the route's URL but for other route not append an
extraneous query param.

Given the following router...
```ruby
Rails.application.routes.draw do
  scope ":account_id" do
    get 'dashboard' => 'pages#dashboard', as: :dashboard
    get 'search/:term' => 'search#search', as: :search
  end
  delete 'signout' => 'sessions#destroy', as: :signout
end
```

And given the following `ApplicationController`
```ruby
  class ApplicationController < ActionController::Base
    def default_url_options
      { bind_params: { account_id: "foo" } }
    end
  end
```

The standard URLHelpers will now behave as follows:

```ruby
dashboard_path # => /foo/dashboard
dashboard_path(account_id: "bar") # => /bar/dashboard
signout_path # => /signout
signout_path(account_id: "bar") # => /signout?account_id=bar
search_path("quin") # => /foo/search/quin
```
2023-05-30 20:47:26 +00:00
Rafael Mendonça França 7eeaadb7fc
Merge pull request #48199 from JoeDupuis/remove-url-rewriter-tests
Remove UrlRewriter tests
2023-05-30 16:03:43 -04:00
Rafael Mendonça França 54de0cb2ee
Merge pull request #48293 from flavorjones/flavorjones-support-html5-sanitizer
Update Action View to use HTML5 standards-compliant sanitizers
2023-05-30 16:00:13 -04:00
zzak 7a014c07e2
Add a tiny more detail about the middleware stack 2023-05-29 16:43:34 +09:00
zzak 2b637b6850
Fix RDoc autolinks in ActionController::Metal 2023-05-29 16:01:00 +09:00
zzak 722d4f6582
Unlink Rails constant from READMEs 2023-05-29 15:14:44 +09:00
zzak 7765a693ee
Fix links for Renderers.add and Renderers.remove 2023-05-29 14:24:10 +09:00
Mike Dalessio 500ccaaeea
Update dependency on rails-html-sanitizer to ~>1.6
for HTML5 sanitizer support
2023-05-28 14:00:35 -04:00
Joé Dupuis acdfef2097 Remove UrlRewriter tests
UrlRewriter has been deleted in 2010 e68bfaf1fe
The url_rewriter_test is really testing url_for. Most of the tests are
identical.

This also move a couple tests that were not present in
`url_for_test.rb`.
2023-05-27 17:01:21 -07:00
Aaron Patterson 861795ed92
Refactor error highlight detection
Before this commit, some calls to render were hard-coding error
highlight as "not available".  This was causing some error pages to show
the "you should install error highlight" message even though the right
version of error highlight was installed.

This commit adds a delegate method to the DebugView class so that the
debugging related templates can just ask whether or not error highlight
is available via a method call.  That way we don't need to rely on
passing locals everywhere.  The down side is that this change requires
all "rescue" templates to be rendered within the context of a DebugView
class (but I think that's OK)
2023-05-25 09:27:35 -07:00
zzak 073269c9b9
Merge pull request #48288 from zzak/rdoc-fixed-width-namespaces
Use short-form fixed-width RDoc form for namespaces
2023-05-25 07:14:47 +09:00
zzak e3c73fd183
Replace all occurrences of '<tt>(\w+::\w+)</tt>' with '+$1+'
E.g.:

* <tt>ActiveRecord::Base</tt> -> +ActiveRecord::Base+

Co-authored-by: Hartley McGuire <skipkayhil@gmail.com>
Co-authored-by: Petrik de Heus <petrik@deheus.net>
2023-05-25 06:52:32 +09:00
Rafael Mendonça França 61accb7dea
Merge pull request #45867 from jdufresne/show-rescuable-exceptions
Make the test environment show rescuable exceptions in responses
2023-05-24 13:45:45 -04:00
Rafael Mendonça França 5e34a9297b
Test behavior in unit test 2023-05-24 17:01:38 +00:00
Zeke Gabrielse 7d8cb154d4 Fix issue with empty values within delimited authorization header
When the Authorization header would contain a set of delimited values
where one or more values were blank, an ArgumentError would be raised.
This resolves that by removing blank values during parsing of the
Authorization header.
2023-05-22 15:27:03 -05:00
Jonathan Hefner 117c2b47b3 Add missing comma [ci-skip] 2023-05-21 16:24:02 -05:00
Guillermo Iguaran b44b881112 Register Mime type for image/webp automatically.
Although we rarely update this list now WebP can be considered
popular enough to be included.
2023-05-20 18:30:26 -07:00
Hartley McGuire d028c14b03
Link rescue_from from modules including Rescuable
Also add some additional words to make it clear that the modules also
implement handling the exceptions configured with rescue_from, because
it was not immediately clear that happened without reading the code.
2023-05-18 12:54:16 -04:00
Jonathan Hefner 4d240e0da3
Merge pull request #48251 from skipkayhil/hm-rm-explicit-alias-doc
Remove explicit "aliased as" documentation [ci skip]
2023-05-18 10:17:14 -05:00
Hartley McGuire b3c6a9adf0
Remove explicit "aliased as" documentation
Most of these are redundant because rdoc handles these itself, but
`titlecase` on `ActiveSupport::Inflector` does not exist so that one is
just incorrect.
2023-05-18 11:04:04 -04:00
Hartley McGuire 5cd144e7fb
Update and fixup ActionController::Parameters docs
- Small wording tweaks for grammar or consistency
- Add links to methods/classes when possible, and fix some cases where
  there were links but shouldn't be (`API`, `Testing`, etc.)
- Fixed `call-seq` for `each_key`
- Change `has_key?`, `key?`, and `member?` to aliases instead of
  delegates so that they are documented as aliases (This is how the
  methods are documented for Hash in Ruby)
- Remove explicit "also aliased as" docs because rdoc does this already
- Add `:nodoc:` to `EMPTY_ARRAY` and `EMPTY_HASH` constants since these
  are internal optimizations
2023-05-18 10:35:42 -04:00
Petrik 72c5a69b5f Clarify X-Cascade header in ShowExceptions middleware [ci-skip]
Clarify that the middleware looks at the `X-Cascade` header in the
response.

Co-authored-by: Hartley McGuire <skipkayhil@gmail.com>
2023-05-17 17:19:10 +02:00
Jon Dufresne e28f147329 Make the test environment show rescuable exceptions in responses
Background
----------

During integration tests, it is desirable for the application to respond
as closely as possible to the way it would in production. This improves
confidence that the application behavior acts as it should.

In Rails tests, one major mismatch between the test and production
environments is that exceptions raised during an HTTP request (e.g.
`ActiveRecord::RecordNotFound`) are re-raised within the test rather
than rescued and then converted to a 404 response.

Setting `config.action_dispatch.show_exceptions` to `true` will make the
test environment act like production, however, when an unexpected
internal server error occurs, the test will be left with a opaque 500
response rather than presenting a useful stack trace. This makes
debugging more difficult.

This leaves the developer with choosing between higher quality
integration tests or an improved debugging experience on a failure.

I propose that we can achieve both.

Solution
--------

Change the configuration option `config.action_dispatch.show_exceptions`
from a boolean to one of 3 values: `:all`, `:rescuable`, `:none`. The
values `:all` and `:none` behaves the same as the previous `true` and
`false` respectively. What was previously `true` (now `:all`) continues
to be the default for non-test environments.

The new `:rescuable` value is the new default for the test environment.
It will show exceptions in the response only for rescuable exceptions as
defined by `ActionDispatch::ExceptionWrapper.rescue_responses`. In the
event of an unexpected internal server error, the exception that caused
the error will still be raised within the test so as to provide a useful
stack trace and a good debugging experience.
2023-05-17 06:30:28 -07:00
Hartley McGuire 781a4a0159
Update and fixup ShowExceptions documentation
This commit adds documentation to ShowExceptions explaining how it
should be configured in Rails applications. In addition, it adds more
`<code>` blocks to fix the formatting of some code snippets and prevent
the page from linking to itself.
2023-05-16 14:06:54 -04:00
Igor S. Morozov 300b8e32c2
Content Security Policy: add `:unsafe_hashes` mapping 2023-05-13 01:48:13 +03:00
Joé Dupuis 4fd27842b8 Remove redundant protocol test for url_for
test_protocol_with_and_without_separators already has the same assertion.
2023-05-11 21:15:03 -07:00
Eileen M. Uchitelle 1769487bc2
Merge pull request #48123 from cpjmcquillan/cm/remove-redundant-test-setup
Remove redundant test
2023-05-09 09:28:36 -04:00
Connor McQuillan db8f573ada
Remove redundant test
This test was introduced in #19904.

In #21368 a bunch of test setup was removed, but the assignment
of `@set` was duplicated.

Removing the extraneous test setup means the test is identical to the
`test_cart_inspect` test.

This removes the test entirely.
2023-05-09 08:33:35 +01:00
Jonathan Hefner c924ba0df9 Support :message_pack as cookies serializer
This commit adds support for `:message_pack` and `:message_pack_allow_marshal`
as serializers for `config.action_dispatch.cookies_serializer`, just
like `config.active_support.message_serializer`.

The `:message_pack` serializer can fall back to deserializing with
`AS::JSON`, and the `:message_pack_allow_marshal` serializer can fall
back to deserializing with `AS::JSON` or `Marshal`.  Additionally, the
`:marshal`, `:json`, and `:hybrid` / `:json_allow_marshal` serializers
can now fall back to deserializing with `AS::MessagePack`.  These
behaviors make it easier to migrate between cookies serializers.
2023-05-08 15:00:08 -05:00
Guillermo Iguaran 06c219710a
Merge pull request #48148 from tindron/arbitrary-hash-arrays
[Fix #38698] Fix nested Arrays when permitting arbitrary Hashes
2023-05-07 22:42:26 -07:00
Guillermo Iguaran 15b662abb5
Merge pull request #48158 from JoeDupuis/fix-rack-3-body-stream-test
Fix failing buildkite build - action_pack [rack-3]
2023-05-07 20:34:55 -07:00
Jean Boussier 583afa1404 Optimize mime types validation in ActionView::LookupContext
Fix: https://github.com/rails/rails/issues/48156

The assumption here is that in the overwhelming majority of
cases, all formats are valid.

So we first check if any of the formats is invalid before duping
the details hash and filtering them.

Additonally, by exposing a (non-public) `valid_symbols?` method, we
can check symbols are valid without resporting to `Array#%` which
would needlessly duplicate the `formats` array.
2023-05-08 10:34:55 +09:00
Jean Boussier 06d2c2d15b Refactor ActionView::Template::Types to avoid delegation
The `Type` class was introduced in https://github.com/rails/rails/pull/23085
for the sole purpose of breaking the dependency of Action View on Action Dispatch.

Unless you are somehow running Action View standalone, this is actually
never used.

So instead of delegating, we can use constant swapping, this saves us
a useless layer.

Ultimately we could consider moving `Mime::Types` into Active Support
but it requires some more thoughts.
2023-05-08 10:34:46 +09:00
Joe Dupuis 5216400529 Fix body stream test on Rack 3.0 by rewinding the body stream.
Since 3.0, Rack doesn't guarantee rewindable request body streams.
Therefore Rack doesn't rewind the body after parsing the POST params
like it use to.
Since this is a test request, we can guarantee the stream is rewindable
and do it in the test.
2023-05-07 17:14:18 -07:00
Randy Stoller 8ed86b7e21
[Fix #38698] Fix nested Arrays when permitting arbitrary Hashes 2023-05-06 13:09:03 -07:00
Jean Boussier d5ff2bf222
Merge pull request #48067 from shouichi/document-flash-delete
document AD::FlashHash#delete [skip ci]
2023-04-27 17:04:05 +02:00
Shouichi Kamiya 7b64a759e1 document AD::FlashHash#delete [skip ci]
Co-authored-by: Seonggi Yang <seonggi.yang@gmail.com>
Co-authored-by: Ryohei UEDA <ueda@anipos.co.jp>
Co-authored-by: oljfte <oljfte@gmail.com>
2023-04-27 13:26:35 +09:00
Jean Boussier 073d90c67d
Merge pull request #47735 from nirebu/nirebu/stop-root-string-allocation-in-helper
Do not allocate the first character when checking for relative paths
2023-04-26 12:08:01 +02:00
Petrik de Heus 40f6c12c24
Merge pull request #48044 from p8/docs/fix-headers
Escape namespaces in some doc headers [ci-skip]
2023-04-24 09:25:00 +02:00
Petrik f89588240f Escape namespaces in some doc headers [ci-skip]
Also move the CSP header from a method to the module.
2023-04-24 09:18:08 +02:00
Gareth Adams 8f3c6a1005 Make Rails cookies RFC6265-compliant with domain: :all
Rails has incorrectly been adding leading dots to cookie domain values
when the `domain: :all` option is present.

This leading dot was required in cookies based on [RFC 2965][rfc2965]
(October 2000), but [RFC 6265][rfc6265] (April 2011) changed that
behaviour, making a leading dot strictly incorrect. Todays browsers aim
to confirm to RFC6265 with repect to cookies.

The new behaviour is that *any* cookie with an explicitly passed domain
is sent to all matching subdomains[[ref][mdn]]. For a server to indicate
that only the exact origin server should receive the cookie, it should
instead pass *no* domain attribute.

Despite the change in behaviour, browser devtools often display a cookie
domain with a leading dot to indicate that it is valid for subdomains -
this prefixed domain is *not* necessarily the raw value that was passed
in the Set-Cookie header. This explains why it's a common belief among
developers that the leading dot is required.

RFC6265 standard gives UAs an algorithm to handle old-style cookie
domain parameters (they can drop a leading dot if present), so it's
unlikely that this error would ever have had any effect on web browsers.

However, cookies generated this way can't be processed by Ruby's own
CGI::Cookie class:

> CGI::Cookie.new "domain" => ".foo.bar", "name" => "foo"
ArgumentError: invalid domain: ".foo.bar"

Newer versions of the Ruby CGI library accomodate the same fallback
behaviour (dropping the extra dot) but this isn't a justification for it
being the right way to set a cookie.

[mdn]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#domain_attribute
[rfc2965]: https://www.rfc-editor.org/rfc/rfc2965#section-3.2
[rfc6265]: https://www.rfc-editor.org/rfc/rfc6265#section-4.1.1
2023-04-24 01:38:34 +01:00
Petrik 48b205989a Cleanup Action Pack documentation headers [ci-skip] 2023-04-22 20:40:39 +02:00
Petrik c0d501e818 Fix some doc headings naming [ci-skip]
Headings should use the name of library instead of the namespace.
2023-04-21 10:15:47 +02:00
Petrik 168c206e06 Add missing headers to Action Pack docs [ci-skip]
Having a h1 heading will improve SEO and makes things look more consistent.
2023-04-20 22:24:43 +02:00
Jonathan Hefner d618a457c4 Replace backticks with RDoc markup [ci-skip]
Follow-up to #47933.

RDoc does not support backticks the way that Markdown does.  Instead,
inline code must be wrapped with `+` or `<tt>`.
2023-04-16 18:26:50 -05:00
Renny Ren 80c6cd871a Update docs about SSE streaming response 2023-04-13 18:13:49 +08:00
zzak fdd0cb8b04
💅 Clean up changelog entry for #47877 2023-04-13 09:40:52 +09:00
Vipul A M bcc2e0c4e4
Merge pull request #47921 from luanzeba/route_source_changelog
Changelog entry for routes source location
2023-04-12 20:45:21 +05:30
Luan Vieira a154a08f2b
Changelog entry for routes source location
Change made in https://github.com/rails/rails/pull/47877
2023-04-12 10:54:40 -04:00
Aaron Patterson 2675c906b1
Merge pull request #47877 from luanzeba/route-source-location
Print source location when inspecting routes
2023-04-11 11:58:47 -07:00
Daniel Colson a00e548da7
Print source location when inspecting routes
In larger route files, or when routes are spread across multiple files,
it can be difficult to get from the output of the route inspector to the
relevant route definition.

This commit adds a route source location to the route, and uses that in
the HtmlTableFormatter (for rails/info and the debug exceptions
middleware) and the Expanded formatter (for `rails routes -E`).

To avoid doing extra work in production, it only sets the source location
in development.

This commit injects the application's backtrace cleaner so we can use it
to remove the rails root from the path. This also means we don't get
source locations for the routes defined by Rails.

If mounting an engine from a gem, we'll get a source location for where
we mount it in the application, but not for the routes defined in the
gem itself. That's probably good enough, since Rails already prints
routes for an engine separately under the title "Routes for
Foo::Engine".

Co-authored-by: John Hawthorn <jhawthorn@github.com>
Co-authored-by: Luan Vieira <luanzeba@github.com>
Co-authored-by: Daniel Colson <composerinteralia@github.com>
2023-04-10 09:52:27 -04:00
zzak 5a4c212aca
Hide Rack internals from API docs 2023-04-06 16:39:38 +09:00
Petrik 3376ab5285 Add documentation intros for Action Controller and Action Dispatch
In 7c94708d24 the READMEs were included for
the main framework pages of the API documentation, except for Action Pack.
As Action Pack doesn't define any code in the ActionPack namespace, only
it's included modules (Action Dispatch, Action Controller and Abstract
Controller) are documented.

This adds documentation intro's to the main page for Action Controller
and Action Dispatch. The content was copied from the Action Pack README.
As Abstract Controller isn't mentioned there, it is skipped for now.
[ci-skip]
2023-04-02 17:34:35 +02:00
Hidde-Jan Jongsma 603b5cdde5 Alias ActionController::Parameters except as without 2023-03-29 10:56:58 +02:00
Rafael Mendonça França acd8fd142d
Merge pull request #47758 from sled/security/set-content-type-charset
Set charset in content type response headers (OWASP)
2023-03-25 11:24:43 -04:00
zzak 57b01b4633
Fix actionpack CHANGELOG lint error 2023-03-25 08:32:26 +09:00
Simon Schmid a9d191997b set charset in content type response headers 2023-03-24 10:17:04 +01:00
Nicolò Rebughini 14c6e04438 Do not allocate the first character when checking for relative paths
This is the same optimization applied in
a63ae913df
which I proposed in https://github.com/rails/rails/pull/47714

Here's the benchmark:

require "bundler/inline"

ROOT_STRING = '/'
TEST_PATH = "/some/path"

gemfile(true) do
  source "https://rubygems.org"

  gem "benchmark-ips"
end

Benchmark.ips do |x|
  x.report("path[0]") do
   TEST_PATH[0] != ROOT_STRING
  end

  x.report("path.start_with?") do
   TEST_PATH.start_with?(ROOT_STRING)
  end

  x.compare!
end

Warming up --------------------------------------
             path[0]   942.044k i/100ms
    path.start_with?     1.556M i/100ms
Calculating -------------------------------------
             path[0]      9.463M (± 0.9%) i/s -     48.044M in   5.077358s
    path.start_with?     15.611M (± 0.2%) i/s -     79.352M in   5.083056s

Comparison:
    path.start_with?: 15611192.8 i/s
             path[0]:  9463245.0 i/s - 1.65x  slower
2023-03-22 16:18:24 +01:00
Andrew Novoselac 6902cbce1b Introducs `TestFixtures#fixture_paths`.
Multiple fixture paths can now be specified using the `#fixture_paths` accessor.
2023-03-14 19:02:56 -04:00
Rafael Mendonça França e64cbf75e9
Merge pull request #47597 from higher-pixels/fix-47535
Fixes 47535 - flag multiple cookies as secure
2023-03-13 13:54:08 -04:00
Jonathan Hefner 4bd6251a15 Remove obsolete AC::Rendering#_normalize_args
The sole purpose of `ActionController::Rendering#_normalize_args` is to
store the given block in `options[:update]`.  This behavior was added
long ago in 6923b392b7 (as [part of
`ActionController::Base#_normalize_options`][part-of]) to support RJS.
Rails no longer supports RJS, so this override is no longer necessary.

[part-of]: 6923b392b7 (diff-febf2f89e7c197d6a9a7077c96031c68b2b7ac4d8ce7ec634de92b164e5f69adR100)
2023-03-10 15:51:54 -06:00
Ron Shinall 45547e1ee7 Fix #47535 - flag multiple cookies as secure 2023-03-08 12:29:26 -05:00
Junichi Sato aacd909b7f
Give documentational consistency to authenticate_with_http_token [ci-skip] 2023-03-07 12:21:54 +09:00
Jason Kotchoff 69d50468cb Expand rails route search to all table content
Expands the search field on the rails/info/routes page to also search:
* Route name (with or without a _path and _url extension)
* HTTP Verb (eg. GET/POST/PUT etc.)
* Controller#Action

because it's not obvious that the search field is currently only
restricted to the route paths.
2023-03-03 17:14:33 +11:00
Rafael Mendonça França 696ccbc265
Remove deprecated `poltergeist` and `webkit` (capybara-webkit) driver registration for system testing 2023-03-03 00:38:23 +00:00
Rafael Mendonça França 1e70d0f5d3
Remove deprecated ability to assign a single value to `config.action_dispatch.trusted_proxies` 2023-03-03 00:38:22 +00:00
Rafael Mendonça França 689b277733
Remove deprecated behavior on `Request#content_type` 2023-03-03 00:38:21 +00:00
Rafael Mendonça França 787b81b620
Merge pull request #47488 from jkotchoff/rails-info-routes-layout-compaction
Line break long routes to prevent scrolling
2023-02-28 17:49:56 -05:00
Matthew Draper 629a32148c
Merge pull request #47477 from ioquatix/rack-3-static-lowercase-headers
Rack 3 static lowercase headers.
2023-02-26 20:33:54 +10:30
Matthew Draper e06844f69b Expect Static to set lowercase values in Vary 2023-02-26 19:36:29 +10:30
Jason Kotchoff b11131868f Line break long routes to prevent scrolling
Prevents horizontal scrolling on the rails/info/routes page when there
are long route names by introducing styled line breaks so that the table
will fit within the rendered width of the browser.

This is particularly relevant when there are a lot of nested namespaces
in a rails project and makes the page more readable, especially when
filtering with a search query.

The table headings have also been left-aligned so that they line up more
intuitively with the content and now that the table is no longer
horizontally scrolling, less space has been explicitly allocated for the
HTTP Verb column.
2023-02-24 05:16:30 +00:00
Nick Borromeo 92216ebb19 Create an ActionView::PathRegistry module
This is a refactor of the `Registry` module added in https://github.com/rails/rails/pull/47347. This is an attempt to
minimize the namespace conflcits that will happen when users will have a top level `Registry` module which can cause
incorrect behavior

Replace ActionView::ViewPaths::Registry with ActionView::PathRegistry
2023-02-23 16:53:57 -08:00
zzak d2af670dba
Remove Copyright years (#47467)
* Remove Copyright years

* Basecamp is now 37signals... again

Co-authored-by: David Heinemeier Hansson <dhh@hey.com>

---------

Co-authored-by: David Heinemeier Hansson <dhh@hey.com>
2023-02-23 11:38:16 +01:00
Samuel Williams 152b6c9986
Prefer lowercase headers in `ActionDispatch::Static`.
`ActionDispatch::Static` uses mixed-case headers and merges them with
lower case headers. This produces duplicate headers. Prefer lowercase
headers to avoid this situation.
2023-02-23 20:24:17 +13:00
Gannon McGibbon 3f4a7734da Set ORIGINAL_FULLPATH header in controller tests
Since rails/rails#47296, nothing sets the fullpath early, so changing
the path of a request, and then calling original_fullpath returns the
updated fullpath. This is a controller testing specific bug as
integration tests and real requests always have this header set, so I
think controller tests should too.
2023-02-22 00:33:09 -06:00
John Hawthorn 28284fc186 Refactor into ViewPaths::Registry 2023-02-16 10:29:17 -08:00
Aaron Patterson 218ec10df8
Merge pull request #47092 from ioquatix/rack-3-streaming-body
Update `ActionDispatch::Response` to support streaming bodies.
2023-02-14 17:01:45 -08:00
Aaron Patterson e89b2e4271
Merge pull request #47147 from ioquatix/rack-3-headers-name-normalization
Normalize usage of "Headers".
2023-02-14 17:01:05 -08:00
zzak 0c71b60cfd
Add test for request.get_header("route_uri_pattern")
Co-authored-by: Rafael Mendonça França <rafael@rubyonrails.org>
2023-02-14 13:55:22 +09:00
Yasuo Honda f838a74212
Merge pull request #46866 from ghousemohamed/change-year-2022-to-2023 2023-02-13 13:15:43 +09:00
Pedro de Jesus c426e46d76 Add body_stream.rewind before reading it on ActionPack::Request 2023-02-10 19:02:19 +00:00
Pedro de Jesus 75126b8dd4 Fix issue #46784 2023-02-10 17:27:49 +00:00
Carlos Antonio da Silva 643c2cbbff Fix changelog example in actionpack
`full_path` is actually `fullpath`, as described in the line above.
`filtered_path` exists only in the `request` object, not `response`.

[ci skip]
2023-02-09 09:08:17 -03:00
Rafael Mendonça França aa3fc0fca2
Merge pull request #47296 from ritikesh/filtered_path
use filtered_path in action_controller event payloads instead of fullpath
2023-02-08 13:29:10 -05:00
Eileen M. Uchitelle d86f75256b
Merge pull request #47310 from olefriis/fix-recognize-path-regression
Fix regression in ActionDispatch::Routing::RouteSet#recognize_path
2023-02-08 08:52:40 -05:00
Petrik 32aba689ef Use Example heading without semicolon [ci-skip]
Make headers more consistent as we almost never add semicolons to the
headers.
2023-02-08 12:08:37 +01:00
Ole Friis Østergaard 1d3edd1c84 Fix regression in ActionDispatch::Routing::RouteSet#recognize_path 2023-02-08 10:49:29 +00:00
zzak f38c21b11e
Use RDoc style for code blocks, instead of markdown 2023-02-08 18:02:42 +09:00
Ritikesh G c59ce2cf71
use filtered_path in action_controller event payloads instead of fullpath 2023-02-08 13:28:32 +05:30
zzak b34e579636
RDoc should go next to the declared module 2023-02-08 15:12:58 +09:00
Koichi ITO 5726b1d1d7 Use RuboCop Performance 1.16.0
## Summary

This PR bumps RuboCop Performance to 1.16.0 and suppresses the following new offenses:

```console
% bundle exec rubocop
(snip)

Offenses:

actionpack/lib/action_dispatch/routing/mapper.rb:309:16:
C: [Correctable] Performance/StringInclude: Use String#include? instead of a regex match with literal-only pattern.
            if /#/.match?(to)
               ^^^^^^^^^^^^^^
actionpack/lib/action_dispatch/routing/mapper.rb:1643:18:
C: [Correctable] Performance/StringInclude: Use String#include? instead of a regex match with literal-only pattern.
              if /#/.match?(to)
                 ^^^^^^^^^^^^^^
actionpack/lib/action_dispatch/routing/route_set.rb:887:67:
C: [Correctable] Performance/StringInclude: Use String#include? instead of a regex match with literal-only pattern.
        path = Journey::Router::Utils.normalize_path(path) unless %r{://}.match?(path)
                                                                  ^^^^^^^^^^^^^^^^^^^^
actionpack/lib/action_dispatch/testing/assertions/routing.rb:86:12:
C: [Correctable] Performance/StringInclude: Use String#include? instead of a regex match with literal-only pattern.
        if %r{://}.match?(expected_path)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
actionpack/lib/action_dispatch/testing/assertions/routing.rb:205:14:
C: [Correctable] Performance/StringInclude: Use String#include? instead of a regex match with literal-only pattern.
          if %r{://}.match?(path)
             ^^^^^^^^^^^^^^^^^^^^
actionpack/lib/action_dispatch/testing/integration.rb:235:12:
C: [Correctable] Performance/StringInclude: Use String#include? instead of a regex match with literal-only pattern.
        if %r{://}.match?(path)
           ^^^^^^^^^^^^^^^^^^^^
actiontext/bin/webpack:18:6:
C: [Correctable] Performance/StringInclude: Use String#include? instead of a regex match with literal-only pattern.
  if /This file was generated by Bundler/.match?(File.read(bundle_binstub, 150))
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
actiontext/bin/webpack-dev-server:18:6:
C: [Correctable] Performance/StringInclude: Use String#include? instead of a regex match with literal-only pattern.
  if /This file was generated by Bundler/.match?(File.read(bundle_binstub, 150))
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb:120:64:
C: [Correctable] Performance/StringInclude: Use String#include? instead of a regex match with literal-only pattern.
          elsif column.type == :uuid && value.is_a?(String) && /\(\)/.match?(value)
                                                               ^^^^^^^^^^^^^^^^^^^^
railties/lib/rails/commands/secrets/secrets_command.rb:28:12:
C: [Correctable] Performance/StringInclude: Use String#include? instead of a regex match with literal-only pattern.
        if /secrets\.yml\.enc/.match?(error.message)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

3088 files inspected, 10 offenses detected, 10 offenses autocorrectable
```

## Additional Information

This behavior change is based on:
https://github.com/rubocop/rubocop-performance/pull/332
2023-02-06 13:06:31 +09:00
Eileen M. Uchitelle 3cca0d5205
Merge pull request #47200 from skipkayhil/use-ad-deprecator-illegal-state
Use AD.deprecator for IllegalStateError
2023-01-31 08:48:59 -05:00
Eileen M. Uchitelle 77d4ce0ade
Merge pull request #47199 from skipkayhil/deprecate-missing-helper-error
Deprecate AbstractController MissingHelperError
2023-01-31 08:48:29 -05:00
Hartley McGuire d1689ef8eb
Use AD.deprecator for IllegalStateError
Previously, ActionDispatch::IllegalStateError was deprecated using
Module#deprecate_constant in 0b4b4c6b96.
This requires the -w flag to be used to actually see the deprecation
warning, and it can not be controlled using ActiveSupport::Deprecator
configuration.

This commit changes the deprecation to use #deprecate_constant from
ActiveSupport::Deprecation::DeprecatedConstantAccessor. This ensures
that the deprecation warning will be printed even without -w, and the
warning can be controlled by configuring ActionDispatch.deprecator
2023-01-31 03:16:20 -05:00
Hartley McGuire ada584bcb8
Deprecate AbstractController MissingHelperError
This error used to be a wrapper for a LoadError raised when
require_dependency was used to load helpers for controllers.

Since Zeitwerk does not use require_dependency, the only usage of the
error was removed in 5b28a0e972.
2023-01-31 02:49:21 -05:00
Hartley McGuire 89a905a798
Rm unused load_error core_ext in Action Controller
It was moved from action_controller/base/helpers.rb to its current
location in 28508d444e. At that time,
there were only two instances of is_missing being used: one in
action_controller/base/helpers and one in action_mailer/base/helpers.rb.

The action_mailer usage was moved to abstract_controller/helpers in
684c2dc208, and the action_controller
usage moved in 0e063f435c. This last
usage was later removed in 5b28a0e972,
leaving the require now unused.
2023-01-31 01:26:25 -05:00
Rafael Mendonça França c8190750f9
Merge PR #47144 2023-01-30 22:53:09 +00:00
Rafael Mendonça França fee1434734
Update CHANGELOG 2023-01-30 19:04:40 +00:00
zzak 2958f3952f
Merge pull request #47162 from stevenharman/document_exceptions_app_error_handling
Document exceptions app error handling
2023-01-29 16:34:15 +09:00
zzak 766564f78f Several fixes for AC::Streaming 2023-01-29 08:35:33 +09:00
zzak f6f52c363b Add Passenger docs for ActionController::Streaming
Originally added in #20811

Co-authored-by: Aditya Kapoor <adityakapoor.mait@gmail.com>
2023-01-28 18:28:57 +09:00
Sean Doyle ad79ed0e6b `ActionDispatch::Testing::TestResponse#parsed_body` parse HTML with Nokogiri
Prior to this commit, the only out-of-the-box parsing that
`ActionDispatch::Testing::TestResponse#parsed_body` supported was for
`application/json` requests. This meant that `response.body ==
response.parsed_body` for HTML requests.

```ruby
get "/posts"
response.content_type         # => "text/html; charset=utf-8"
response.parsed_body.class    # => Nokogiri::HTML5::Document
response.parsed_body.to_html  # => "<!DOCTYPE html>\n<html>\n..."
```

Using `parsed_body` for JSON requests supports `Hash#fetch`, `Hash#dig`,
and Ruby 3.2 destructuring assignment and pattern matching.

The introduction of [Nokogiri support for pattern
matching][nokogiri-pattern-matching] poses an opportunity to make assertions
about the structure of the HTML response.

On top of that, there is ongoing work to [introduce pattern matching
support in MiniTest][minitest-pattern-matching].

[nokogiri-pattern-matching]: https://github.com/sparklemotion/nokogiri/pull/2523
[minitest-pattern-matching]: https://github.com/minitest/minitest/pull/936
2023-01-27 23:52:21 -05:00
Michael Hadley c22e20e79c Fix typo in `assume_ssl` configuration guide 2023-01-27 19:09:38 -08:00
Steven Harman af1019cecd
Fix typo: missing end brackets 2023-01-27 12:53:57 -05:00
Samuel Williams a3caa2b551
Normalize usage of "Headers". 2023-01-26 12:06:24 +13:00
Rafael Mendonça França 2cf8740e15
Merge pull request #47091 from ioquatix/rack-3-case-insensitive-headers
Use Rack's own headers classes where appropriate.
2023-01-25 17:22:47 -05:00
Joel Hawksley 2fc46f95a5
Tag HTTP::Request with route URI pattern (#47129)
In the GitHub RoR monolith, we output the route URI pattern
in an HTML meta tag in our application layout for analysis
purposes. However, our current implementation is quite manual.

This change adds an attribute to requests with the URI pattern
of the matched route.

Co-authored-by: Rafael Mendonça França <rafael@rubyonrails.org>
Co-authored-by: Kate Higa <khiga8@github.com>
2023-01-25 16:43:12 -05:00
Rafael Mendonça França e572f23150
Merge pull request #47094 from zzak/rack-3-files-continued
Replace deprecated Rack::File with Rack::Files
2023-01-25 16:41:12 -05:00
David Heinemeier Hansson 8b8ac378a9 Trailing whitespace 2023-01-25 21:27:16 +01:00
Rafael Mendonça França 1b44989521
Merge PR #46594 2023-01-25 20:13:18 +00:00
David Heinemeier Hansson 1da6f8c68e
Allow use of SSL-terminating reserve proxy that doesn't set headers (#47139)
* Allow use of SSL-terminating reserve proxy that doesn't set headers

NGINX and other SSL-terminating reverse proxies can use HTTP headers to include forwarding information. If your stack includes SSL-termination through a network load balancer, that won't happen. You can use config.assume_ssl to address that.

* I hate these warts

* Document the new setting

* Add autoload for AssumeSSL

* Add CHANGELOG notice
2023-01-25 21:02:02 +01:00
Rafael Mendonça França 859b526c5b
Remove upper bound of rack
Allow users to install any version and try to see if Rails is compatible.
2023-01-25 15:25:49 +00:00
zzak 896c7faedf Use Gemfile to manage Rack version for dev 2023-01-25 12:24:19 +09:00
John Hawthorn f6e36c90aa
Merge pull request #47087 from jhawthorn/cookie_domain
Fix cookie domain for `domain: all` on two letter single level TLD
2023-01-24 13:56:38 -08:00
John Hawthorn 941e0cd212 Fix cookie domain calculation for two letter tld 2023-01-23 16:37:16 -08:00
Ron Shinall 189e4108c5 Address Selenium :capabilities deprecation warning 2023-01-23 21:40:01 +00:00
zzak 12de399ef9 Replace deprecated Rack::File with Rack::Files
Follow up to #47075
2023-01-21 09:34:21 +09:00
Samuel Williams 89df368e4d
Update `ActionDispatch::Response` to support streaming bodies.
Rack 3 introduces streaming bodies, which don't respond to `#each` and
MUST respond to `#call`. Ensure that the methods are correctly delegated.

`#to_ary` must also work correctly for enumerable bodies, and is used by
middleware like `Rack::ETag` to buffer enumerable bodies correctly.
2023-01-21 13:12:24 +13:00
Samuel Williams 0b4b4c6b96
Use Rack's own headers classes where appropriate.
Rack 3 response headers must be a mutable hash with lower-case keys. Rack
provides `Rack::Headers` as a compatibility layer for existing systems
which don't conform to this requirement. Prefer `Rack::Utils::HeaderHash`
on Rack 2, and `Rack::Headers` on Rack 3.


Remove some of the response test cases which test `nil` header keys as
these are considered invalid, and will fail with `Rack::Headers`.
2023-01-21 12:55:06 +13:00
Rafael Mendonça França 72642bd74b
Merge pull request #47081 from ioquatix/rack-3-query-parser-utf8
Don't assume that invalid UTF-8 will raise an error.
2023-01-20 15:20:42 -05:00
Rafael Mendonça França 3adec8df0a
Merge pull request #47083 from ioquatix/rack-3-ssl_test-headers
Don't assume the existance of `Rack::Utils::HeaderHash`.
2023-01-20 15:14:19 -05:00
Rafael Mendonça França 4c7c69d1fe
Merge pull request #47082 from ioquatix/rack-3-env-fields
Don't assume these fields will be present in a rack env.
2023-01-20 15:03:52 -05:00
Rafael Mendonça França 8c11ae0440
Avoid redefining the `response=`.
In `6d5e0d2de2a8836e858962981c34aff2f76ffe3d` we added a `response=` method
that was redefining the already existed method generated by `attr_internal`.
2023-01-20 19:31:37 +00:00
Rafael Mendonça França 006d68eb8c
Merge pull request #47079 from ioquatix/actiondispatch-request-inspect
Fix `#inspect` failures when dealing with requests with `method=nil`.
2023-01-20 14:16:36 -05:00
Rafael Mendonça França f43a088b78
Merge pull request #47077 from ioquatix/rack-3-rewindability
Don't assume Rack input supports rewindability.
2023-01-20 14:10:54 -05:00
Rafael Mendonça França 0e615275a6
Merge pull request #47085 from ioquatix/rack-3-compatible-cookies
Don't assume the existance of `add_cookie_to_header` and related methods.
2023-01-20 14:09:12 -05:00
Aaron Patterson db2463f277
Merge pull request #47075 from ioquatix/rack-3-files
Rack deprecated `Rack::File` and replaced it with `Rack::Files`.
2023-01-20 09:49:41 -08:00
Samuel Williams 4c58755862
Add `rack-session` and `rackup` gems.
Rack 2 includes this code, but in Rack 3 it was extracted into gems. These
gems include a v1 release compatible with Rack 2, and a v2 release
compatible with Rack v3+.
2023-01-21 06:03:41 +13:00
Samuel Williams 706fb10ad5
Don't assume the existance of `add_cookie_to_header` and related methods.
Rack 3 deprecates some of these clunky methods, and the only compatible
methods between Rack 2 and Rack 3 is to use `Rack::Response` which
includes `set_cookie` and `delete_cookie`.
2023-01-21 05:59:22 +13:00
Samuel Williams fc0ec10272
Don't assume the existance of `Rack::Utils::HeaderHash`.
In Rack 3, this was deprecated and replaced with `Rack::Headers`. Using a
hash instance here appars to be sufficient.
2023-01-21 05:56:15 +13:00
Samuel Williams 7981dce06c
Don't assume these fields will be present in a rack env.
Rack 3 drops several of these fields as mandatory.
2023-01-21 05:53:20 +13:00
Samuel Williams fd48e72518
Don't assume that invalid UTF-8 will raise an error.
Rack 3 parses the query part of a URL as ASCII-8BIT and does not fail on
invalid UTF-8 code sequences. Limit the tests to Rack 2.
2023-01-21 05:51:29 +13:00
Samuel Williams cc3f50702f
Fix `#inspect` failures when dealing with requests with `method=nil`.
When I was debugging `ActionDispatch::Request` instances in some tests, I
noticed IRB complaining that the object did not support `#inspect`, as
it was trying to print out the `method` which calls `check_method(nil)`
which fails. Don't try to validate `nil` method as it will always fail
and appears to be a valid state (when constructing an empty request as in
some tests).
2023-01-21 05:44:43 +13:00
Samuel Williams 911556fd81
Don't assume Rack input supports rewindability.
Rack 3 drops the requirement for a Rack input body to be rewindable. Limit
the related tests to run only on Rack < 3.
2023-01-21 05:38:54 +13:00
Samuel Williams d4bf3ff6d1
Rack deprecated `Rack::File` and replaced it with `Rack::Files`. 2023-01-21 05:31:41 +13:00
Samuel Williams 08510b5437
Improve matching of headers assertions.
The current implementation makes assumptions about the case and format of
headers. Introduce methods to handle headers in a case insensitive manner
and reduce churn when comparing with multi-value headers.
2023-01-21 05:26:22 +13:00
Samuel Williams f63a5e7d16
Improve matching of cookie assertions.
The current implementation makes assumptions about the order and case
sensitivity of cookie attributes. Introduce methods to parse those fields
and compare them semantically. Update the existing tests to take advantage
of these new assertions.
2023-01-20 14:53:18 +13:00
Rafael Mendonça França 7c38258f70
Merge pull request #46327 from elliotcm/elliotcm/fix-stream-content-type
Fix content-type header with `send_stream`
2023-01-18 15:32:48 -05:00
Jean Boussier 66227e01e7 Improve Rails' Shape friendliness (third pass)
Followup: https://github.com/rails/rails/pull/47023

```
Shape Edges Report
-----------------------------------
snip...
       130  @_config
snip...
        99  @_url_options
```
2023-01-18 15:44:08 +01:00
Rafael Mendonça França 9ecc8785ef
Fix rubocop violations 2023-01-17 19:51:40 +00:00
John Hawthorn 13016ce16e Avoid regex backtracking on If-None-Match header
[CVE-2023-22795]
2023-01-17 11:38:11 -08:00
sabulikia fbc24520a3 Use string#split instead of regex for domain parts
[CVE-2023-22792]
2023-01-17 11:38:11 -08:00
wonda-tea-coffee f6cdce50d4 Fix sec issue with _url_host_allowed?
Disallow certain strings from `_url_host_allowed?` to avoid a redirect
to malicious sites.

[CVE-2023-22797]
2023-01-17 11:38:11 -08:00
Petrik de Heus c975051746
Merge pull request #47029 from hahmed/ha/fix-routing-wording-in-doc [ci-skip]
Update docs in actionpack to use bin/rails
2023-01-17 16:34:50 +01:00
Jean Boussier aa7d78d9b1 Improve Rails' Shape friendliness (second pass)
Followup: https://github.com/rails/rails/pull/47023

```
Shape Edges Report
-----------------------------------
snip...
       238  @errors
snip...
       219  @options
snip...
       129  @_request
       128  @type
       125  @virtual_path
       124  @_assigns
       123  @_config
       123  @_controller
       123  @output_buffer
       123  @view_flow
       122  @_default_form_builder
snip...
        89  @_already_called
        75  @validation_context
snip...
        65  @_new_record_before_last_commit
snip...
        58  @_url_options
snip...
```
2023-01-17 13:55:49 +01:00
Haroon Ahmed 2303628189 Update doc to use bin/rails which is the correct convention for invoking rails commands 2023-01-17 09:42:38 +00:00
Rafael Mendonça França 03a1da9c34
Merge pull request #46915 from joshuay03/update-action-pack-render-template-tests
Update `ActionPack` render template with locals tests
2023-01-16 18:40:27 -05:00
Jean Boussier fc950324bd Improve Rails' Shape friendliness
Ruby 3.2 significantly changed how instance variables are store.
It now use shapes, and in short, it's important for performance
to define instance variables in a consistent order to limit the
amount of shapes.

Otherwise, the number of shapes will increase past a point where
MRI won't be able to cache instance variable access. The impact
is even more important when YJIT is enabled.

This PR is data driven. I dump the list of Shapes from Shopify's
monolith production environment, and Rails is very present among
the top offenders:

```
Shape Edges Report
-----------------------------------
       770  @default_graphql_name
       697  @own_fields
       661  @to_non_null_type
       555  @own_interface_type_memberships
       472  @description
       389  @errors
       348  @oseid
       316  @_view_runtime
       310  @_db_runtime
       292  @visibility
       286  @shop
       271  @attribute_method_patterns_cache
       264  @namespace_for_serializer
       254  @locking_column
       254  @primary_key
       253  @validation_context
       244  @quoted_primary_key
       238  @access_controls
       234  @_trigger_destroy_callback
       226  @_trigger_update_callback
       224  @finder_needs_type_condition
       215  @_committed_already_called
       214  @api_type
       203  @mutations_before_last_save
       202  @access_controls_overrides
       201  @options
       198  @mutations_from_database
       190  @_already_called
       183  @name
       179  @_request
       176  @own_arguments
       175  @_assigns
       175  @virtual_path
       174  @context
       173  @_controller
       173  @output_buffer
       173  @view_flow
       172  @_default_form_builder
       169  @cache
       159  @_touch_record
       151  @attribute_names
       151  @default_attributes
       150  @columns_hash
       149  @attribute_types
       148  @columns
       147  @marked_for_same_origin_verification
       146  @schema_loaded
       143  @_config
       143  @type
       141  @column_names
```

All the changes are of similar nature, the goal is to preset the instance
variable to nil when objects are allocated, or when classes are created.

For classes I leverage the `inherited` hook. If the patern becomes common enough
it might make sense to add a helper for this in `ActiveSupport::Concern`.
2023-01-16 12:31:37 +01:00
eileencodes d9dd1c59d0
Implement spot and don't use `keep_script_lines` in Ruby 3.2
We want to use error highlight with eval'd code, specifically ERB
templates.

Previously we could only get the information we needed by setting
`keep_script_lines` to true. In Ruby 3.2 and error_highlight we added
the ability to get this information without setting `keep_script_lines`.

This change implements that new behavior for Rails.

I removed the script line changes to support this in 3.1 because it is
not in any released version.

Ruby change: https://github.com/ruby/ruby/pull/6593
Erorr highlight change: https://github.com/ruby/error_highlight/pull/26

Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
2023-01-13 16:20:09 -05:00
Lachlan Sylvester 0a77b32042 discard marshal dumped values when reading a signed cookie 2023-01-13 10:47:01 +11:00
Fabian Mersch e768fc8ab8 Scope generated route helpers to an instance of RoutesProxy 2023-01-12 15:03:57 +01:00
Roman Sokhan b7d7376df1 Fix rare conflict of default_render with Minitest::Mock 2023-01-11 18:24:15 +02:00
Samuel Williams 28c8e2229f
Be more explicit when wrapping in an enumerable body. 2023-01-09 13:26:53 +13:00
Samuel Williams 36e2cb9abb
Test body proc detection. 2023-01-09 13:26:53 +13:00
Samuel Williams 5af76309ef
Close previous response if any. 2023-01-09 13:26:53 +13:00
Samuel Williams dc9c0859c0
Allow assigning streaming response body. 2023-01-09 13:26:53 +13:00
Samuel Williams 8e8695ea57
Fix comment. 2023-01-09 13:26:53 +13:00
Samuel Williams 6d5e0d2de2
Limit changes to new interface, `response=`. 2023-01-09 13:26:53 +13:00
Samuel Williams d8256ff62f
Fix test name. 2023-01-09 13:26:53 +13:00
Samuel Williams c239d6d79c
Spaces inside brackets. 2023-01-09 13:26:53 +13:00
Samuel Williams ec3830d54a
Add some tests. 2023-01-09 13:26:52 +13:00
Samuel Williams 49053fe8c0
Direct support for assigning to `self.response`. 2023-01-09 13:26:52 +13:00
Jonathan Hefner aaf7bed003 Document ActionController::Rendering#render [ci-skip]
In #33418, documentation from `ActionView::Helpers::RenderingHelper#render`
was copied to `ActionController::Renderer#render` with the intention of
documenting `ActionController::Rendering#render`.  Since then, further
documentation has been added to `ActionController::Renderer#render`, and
`ActionController::Renderer#render` has been mistaken for
`ActionController::Rendering#render` (for example, in #46045).

This commit adds documentation to `ActionController::Rendering#render`
(which was previously `:nodoc:` because it is a simple override of
`AbstractController::Rendering#render`), and updates related
documentation to point to `ActionController::Rendering#render`.
2023-01-08 15:47:31 -06:00
Jonathan Hefner 6969cdc969 Revise ConditionalGet#expires_in doc [ci-skip] 2023-01-08 15:47:31 -06:00
Jonathan Hefner 2cb419f220 Clean up ConditionalGet#stale? doc [ci-skip] 2023-01-08 15:47:31 -06:00
Jonathan Hefner 657f214f25 Clean up ConditionalGet#fresh_when doc [ci-skip] 2023-01-08 15:47:31 -06:00
Jonathan Hefner 9a82d9585c Replace RFC 2616 links [ci-skip]
The w3.org RFC 2616 page displays an obtrusive "This document has been
superseded" overlay.  In regard to the `Cache-Control` header, RFC 2616
has been superseded by RFC 7234, which, in turn, has been superseded by
RFC 9111.

Therefore, this commit replaces links to RFC 2616 with links to either
MDN or RFC 9111.
2023-01-08 15:47:31 -06:00
Jonathan Hefner ce23110829 Coordinate FilterParameters and ParameterFilter docs [ci-skip]
This clarifies the `ActiveSupport::ParameterFilter` documentation, and
tweaks the example code to be more friendly to the syntax highlighter
(similar to the tweaks made for `ActionDispatch::Http::FilterParameters`
in 782bed5d45).

This also trims the `ActionDispatch::Http::FilterParameters`
documentation, and links it to `ActiveSupport::ParameterFilter`, since
`ActiveSupport::ParameterFilter` is responsible for filter behavior.
2023-01-08 15:47:20 -06:00
Jonathan Hefner 1aba8f64bf Document AD::Request::RFC* constants individually [ci-skip]
Prior to this commit, the list of RFCs and URLs was jumbled in a single
paragraph (with no delimiters) that was associated with the `RFC2616`
constant.

This commit splits up the list, associating each RFC with its respective
constant, and incorporating each URL into a link.
2023-01-08 15:47:20 -06:00
Jonathan Hefner cfe300ceb1 Format inline code [ci-skip] 2023-01-08 15:47:20 -06:00
Jonathan Hefner 3eadf057db Fix typos in API docs [ci-skip] 2023-01-08 15:47:20 -06:00
Jonathan Hefner 33557c5dca Indent private methods in code examples [ci-skip]
This matches the indentation used in generated code, such as code from
`railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb.tt`.
2023-01-08 15:47:20 -06:00
Jean Boussier 481c169aa5
Merge pull request #46910 from skipkayhil/more-string-include
Fix Performance/StringInclude that RuboCop can't
2023-01-07 14:32:49 +01:00
Joshua Young 7e351255c0 [Closes #46724] Update ActionPack render template with locals tests 2023-01-07 12:04:37 +10:00
Akira Matsuda e0936d99a3
Revert "One less String allocation for event.allocations"
This reverts commit ae569eaef8.

Seems like this broke Action View CI
2023-01-07 06:00:21 +09:00
Hartley McGuire 583ce94c22
Fix Performance/StringInclude that RuboCop can't
This replaces two instances of /html/.match?(<string>) with the more
performant <string>.include?("html").

Performance/StringInclude was enabled in 3158bbb, however RuboCop does
not flag these two because it is unable to determine that the variable
passed to #match? is a string. In both these cases we know that the
variable must be a string (Mime::Type must be initialized with a string,
and Content-Type must be a string if present per Rack SPEC)

These were found by `rg '/\[\w ]+/\.match\?'`, and while this search
returns other entries they are either comments or in test files.
2023-01-06 15:52:32 -05:00
Akira Matsuda ae569eaef8
One less String allocation for event.allocations 2023-01-07 04:54:32 +09:00
Jean Boussier dcb4f4d557
Merge pull request #46862 from skipkayhil/lint-ad-integration
Fix IntegrationTest not following Rack SPEC
2023-01-06 16:36:32 +01:00
Hartley McGuire eef4e755e0
Changelog for 0019dea
As this is a user facing change, it should have a changelog entry
2023-01-05 17:43:15 -05:00
Junichi Sato 6f1f2d74e6
Tweak doc to show helper methods need not be public [ci-skip] 2023-01-05 16:19:36 +09:00
Akira Matsuda bfb0a6c211
require active_support/test_case instead of minitest
because this file references AS::TestCase which already loads minitest.
2023-01-05 02:15:10 +09:00
eileencodes 04e1a0d2e1
Add documentation for #43487
In #43487 we missed adding a changelog so that's been added here. In
addition, since this isn't a new framework default unless you are
creating a new application (and only in dev and test environments by
default) it can be easy to miss this new option. I've updated the
message to mention the option following DHH's suggestion on the original
PR.
2023-01-03 13:40:28 -05:00
Ghouse Mohamed e0559d2c1c Change 2022 -> 2023 2023-01-03 13:22:00 +05:30
Hartley McGuire 060887d4c5
Fix IntegrationTest not following Rack SPEC
Previously, ActionDispatch::IntegrationTest would always set
CONTENT_TYPE on the request whether or not the value being set was a
string or nil. However, Rack SPEC requires that if CONTENT_TYPE is set,
it must be a string.

Since the request_encoder can return nil for #content_type (and the
IdentityEncoder always will), IntegrationTest must check before it sets
the CONTENT_TYPE value.

A Rack::Lint test has been added to prevent regressions. Additionally,
it will make changes needed for Rack 3 more obvious when the time comes.
2022-12-30 16:19:25 -05:00
Matthew Draper 0f0ec9908e
Merge pull request #46792 from codeminator/fix-flaky-tests
Increase `socket_timeout` for Memcached inside memcached tests
2022-12-27 17:45:33 +10:30
Yasuo Honda 15576ddedb
Merge pull request #46800 from the-spectator/prefer_local_env
Prefer using new Rails.env.local?
2022-12-24 08:40:42 +09:00
Akira Matsuda a790203408
Use Kernel#Array to avoid an extra Array allocation when nil was given 2022-12-23 23:34:34 +09:00
Akshay Birajdar c312bb7e04 Prefer using new shorthand helper Rails.env.local? 2022-12-23 19:04:33 +05:30
RobL 83da2e9383 Allow proc for per-request cookie domain
Per-request cookie domain set through proc
2022-12-22 19:49:22 +00:00
Ahmed Shahin c2f6be12a5 increase for more tests 2022-12-22 15:04:05 +02:00
Akira Matsuda 15ab7223c7
Avoid creating an extra Hash object when no options were given 2022-12-22 18:26:27 +09:00
Akira Matsuda 055f71cece
Reduce a String object allocation 2022-12-22 17:31:12 +09:00
Akira Matsuda 41c2c26dc6
Reuse the Array object passed from parent middleware
This patch reduces Array object allocations from some Rack middleware per each
request by reusing the Array object that wraps status, headers, and body
objects. This is a Rails version of the same improvements that has already been
pushed to Rack 3.0. https://github.com/rack/rack/pull/1887
2022-12-19 23:04:04 +09:00
Akira Matsuda 8b617e224b
Reduce Array allocations in MimeNegotiation 2022-12-18 12:11:34 +09:00
Akira Matsuda 01001028df
Revert "Reduce more Array object creations"
This reverts commit cac0e04313.

Reason: web-console gem expects the existence of `filter_proxy` and overrides this method
https://github.com/rails/web-console/blob/v4.2.0/lib/web_console/request.rb#L31-L36
2022-12-17 19:00:57 +09:00
Akira Matsuda 4fbc4bbe43
Revert "👮"
This reverts commit 59728911e4.
2022-12-17 18:57:10 +09:00
Akira Matsuda 56333f3c69
Avoid returning "" which is not a valid MIME type 2022-12-17 16:35:25 +09:00
Akira Matsuda 26f51f36fa
No need to reset_body where setting the body soon afterwards 2022-12-17 15:52:18 +09:00
Akira Matsuda bc3251f1be
Reduce `formats` call which creates extra Array objects per each call 2022-12-17 15:52:18 +09:00
Akira Matsuda 78599ba1e8
'string'[0, index] is faster and more eco-friendly than 'string'.split.first 2022-12-17 15:48:00 +09:00
Jonathan Hefner 40b1c60872
Merge pull request #46752 from swanson/forgery-docs-update
Update RequestForgeryProtection docs to encourage wrapper method for skipping [ci-skip]
2022-12-16 11:21:48 -06:00
matt swanson a7bbbc1589 Update docs to encourage use of wrapper method
Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2022-12-16 12:10:57 -05:00
Akira Matsuda 59728911e4
👮 2022-12-16 22:20:58 +09:00
Akira Matsuda b368c68c6a
Reduce Array object allocation 2022-12-16 20:22:07 +09:00
Akira Matsuda 4e7620b110
Unused default value that creates an Array object per each invocation 2022-12-16 20:21:22 +09:00
Akira Matsuda 9a8d2de95b
Avoid duplicating HWIA and reduce object allocations 2022-12-16 20:20:03 +09:00
Akira Matsuda 351e726be5
Reduce Hash allocations 2022-12-16 20:20:03 +09:00
Akira Matsuda cac0e04313
Reduce more Array object creations 2022-12-16 20:20:03 +09:00
Akira Matsuda b9fe288d6d
Reduce Array object allocations 2022-12-16 20:20:03 +09:00
Jonathan Hefner 93038baad7 Use routes.default_url_options in AC::Renderer env
When a host is not specified for an `ActionController::Renderer`'s env,
the host and related options will now be derived from the routes'
`default_url_options` and `ActionDispatch::Http::URL.secure_protocol`.

For example, with:

  ```ruby
  Rails.application.default_url_options = { host: "rubyonrails.org" }
  Rails.application.config.force_ssl = true
  ```

Before:

  ```ruby
  ApplicationController.renderer.render inline: "<%= blog_url %>"
  # => "http://example.org/blog"
  ```

After:

  ```ruby
  ApplicationController.renderer.render inline: "<%= blog_url %>"
  # => "https://rubyonrails.org/blog"
  ```

As a consequence, Action Text attachment URLs rendered in a background
job (a la Turbo Streams) will now use `Rails.application.default_url_options`.

Fixes #41795.
Fixes hotwired/turbo-rails#54.
Fixes hotwired/turbo-rails#155.
2022-12-15 16:22:07 -06:00
Akira Matsuda c0f16c16a3
Defer creation of Request object until the object is in need 2022-12-15 11:55:03 +09:00
Akira Matsuda 41b3e61735
Defer creating Request object until the object is in need in the exceptional case 2022-12-15 11:55:03 +09:00
Alex Ghiculescu 090d1acfe4 Query Logs: `namespaced_controller` tag should match `controller` format
Currently if you do this:

```ruby
config.active_record.query_log_tags = [:namespaced_controller]
```

A request that's processed by the `NameSpaced::UsersController` will log as `namespaced_controller='NameSpaced%3A%3AUsersController'`.

By contrast if you set the tag to `:controller` it would log as `controller='user'`, much nicer.

This PR makes the `:namespaced_controller` formatting more similar to `:controller` - it will now log as `namespaced_controller='name_spaced/users'`.
2022-12-12 10:31:00 -06:00
Jean Boussier 51e9fa9bf9
Merge pull request #46614 from Cofense/action_dispatch-response-buffer-write-alias
Add `#<<` alias for `#write` to ActionDispatch::Response::Buffer
2022-12-08 11:18:09 +01:00
Alex Ghiculescu 03394484a6 Fix more double logging in `ActiveRecord::QueryLogs`
ref: https://github.com/rails/rails/pull/46279

That PR missed the case where if you set `config.active_record.query_log_tags = [:namespaced_controller]`, it would log the controller twice:

```
/*namespaced_controller:Foo::BarController,controller:bar*
```

So this PR just fixes that bug, and tweaks the changelog entry rather than adding another one for the same bug.
2022-12-04 20:57:34 -06:00
Jonathan Hefner 3658dc8af8 Preallocate default Rack env for AC::Renderer
This preallocates a `DEFAULT_ENV` Rack env for `Renderer` instances to
use, and avoids `dup`ing the `DEFAULTS` Hash unless the user intends to
modify it.  This reduces retained allocations per controller class.

**Benchmark**

  ```ruby
  # frozen_string_literal: true
  require "benchmark/memory"

  $controllers = []

  Benchmark.memory do |x|
    Class.new(ActionController::Base) # warmup

    x.report("1 controller") do
      $controllers << Class.new(ActionController::Base)
    end

    x.report("100 controllers") do
      100.times { $controllers << Class.new(ActionController::Base) }
    end
  end
  ```

**Before**

  ```
  Calculating -------------------------------------
          1 controller    16.070k memsize (     9.683k retained)
                         133.000  objects (    40.000  retained)
                          50.000  strings (    14.000  retained)
       100 controllers     1.607M memsize (   875.044k retained)
                          13.300k objects (     3.308k retained)
                          50.000  strings (    50.000  retained)
  ```

**After**

  ```
  Calculating -------------------------------------
          1 controller    15.654k memsize (     9.347k retained)
                         129.000  objects (    38.000  retained)
                          49.000  strings (    14.000  retained)
       100 controllers     1.565M memsize (   841.284k retained)
                          12.900k objects (     3.108k retained)
                          50.000  strings (    50.000  retained)
  ```

This does add a `dup` to `render` because `request.routes = ...` mutates
the underlying env, which can now be `DEFAULT_ENV`.  But a temporary
allocation there (likely outside of a request cycle) seems like a
reasonable trade for avoiding two retained allocations per controller
class.
2022-11-30 16:48:06 -06:00
Eddie Lebow 3eb8493024
Add `#<<` alias for `#write` to ActionDispatch::Response::Buffer
This makes the stream object a closer analog of an `IO`.

on-behalf-of: @Cofense <oss@cofense.com>
2022-11-29 18:00:23 -05:00
Étienne Barrié 3d6a7b2faa Initialize deprecators before configuring them
Since engine initializers run later in the process, we need to run this
initializer earlier than the default.

This ensures they're all registered before the environments are loaded.
2022-11-28 10:47:26 +01:00
Jonathan Hefner a2174bd260 Revise ActionController::Renderer API docs [ci-skip]
This fixes a few inaccuracies that have been present since
2db7304c2c.  For example,
`Controller.renderer` no longer returns a class, `Renderer#env` is not
defined, and changing the value of `Renderer#defaults` has no direct
effect.  This also documents the user-friendly Rack env key variants.
2022-11-27 15:05:33 -06:00
Andy Waite 0ec8f21bb6
Add details of cookie name and size to `CookieOverflow` exception
My app was raising a `CookieOverflow` exception but it was difficult to pinpoint the cause, since error trackers and logging system generally filter out cookies.

This Pull Request has been created because I want the exception to provide additional information:
- The name of the cookie that overflowed
- The magnitude of how much it overflowed by

I am assuming that only the cookie value is sensitive, and not its name or size.
2022-11-24 17:18:02 -05:00
Jonathan Hefner 7bcca5b763 Use memoized dup of url_helpers for reinclusion
In the case where a controller subclasses an engine's controller that,
in turn, subclasses a controller that includes the application's
`url_helpers` (for example, in the "isolated engine routes and helpers
are isolated to that engine" test in `railties/test/railties/engine_test.rb`),
this commit avoids allocating a new module per controller:

  ```ruby
  ActionController::Base.include Rails.application.routes.url_helpers
  C1 = Class.new(ActiveStorage::DirectUploadsController)
  C2 = Class.new(ActiveStorage::DirectUploadsController)

  C1.ancestors - C2.ancestors
  # BEFORE:
  # => [C1, #<Module:0x...>]
  # AFTER:
  # => [C1]
  ```

This commit also modifies the `RouteHelperIntegrationTest` test to use
the controllers defined in `actionpack/test/abstract_unit.rb`.
Otherwise, `extend AbstractController::Railties::RoutesHelpers.with(...)`
happens twice -- once for `ActionController::Base` and once for
`FakeACBase` -- which causes `FooController` to include an extra module
as it flip-flops its `_routes` definition.  Previously, the extra module
only defined a `_routes` method; now, the extra module would be the
memoized dup of `routes.url_helpers`, which would cause the "only
includes one module with route helpers" test to falsely fail.
2022-11-19 10:57:21 -06:00
Jonathan Hefner d69501a3d6 Update ActionController::UrlFor request contract [ci-skip]
Using a `request` object that only "responds to the `host`,
`optional_port`, `protocol`, and `symbolized_path_parameter` methods"
has not been possible for a long time.  For example,
`symbolized_path_parameter` was renamed to `path_parameters` (without
deprecation) in 925bd97566.  And
`request.routes` and `request.original_script_name` methods became
required in 87a7591064.  And a
`request.engine_script_name` method became required in
4080dd2f24.

Therefore, this commit updates the documentation to simply require
an `ActionDispatch::Request` instance.
2022-11-15 13:57:15 -06:00
Jonathan Hefner 782bed5d45 Tweak AD::Http::FilterParameters code example [ci-skip]
Prior to this commit, the format of the code example confused the syntax
highlighter.  This commit formats each explanation as a code comment,
and tweaks their wording for clarity.
2022-11-15 13:57:15 -06:00
Jonathan Hefner 8b216e89cf Replace ActionController::UrlFor references [ci-skip]
These references were missed when `ActionController::UrlFor` was
converted to `ActionDispatch::Routing::UrlFor` in
226dfc2681.
2022-11-15 13:57:15 -06:00
Jonathan Hefner ee8d9497dd Auto-link code references [ci-skip] 2022-11-15 13:57:15 -06:00
Jonathan Hefner 9588f780dc Format inline code [ci-skip] 2022-11-15 13:57:15 -06:00
Jonathan Hefner cb34c92a2b Fix typos [ci-skip] 2022-11-15 13:57:15 -06:00
takayamaki / fusagiko ee389f56ef refactor ParameterEncodingTest and add test for param_encoding
- rename testcases
- reduce redundant parameters
- rename tested action methods
- move skip_parameter_encoding near by definiton of action
- add test for param_encoding
2022-11-14 17:58:18 +00:00
Niklas Haeusele ba16325c96 Improve the MissingExactTemplate errorpage
Passthrough the controller and action name to the error page.
2022-11-10 22:39:09 +01:00
sampatbadhe 61ceeacf0c Correct missing template error page
- Correct controller path "app/controller/books_controller.rb" to "app/controllers/books_controller.rb"
- Add space after "NOTE:"

Ref - https://github.com/rails/rails/pull/46342
2022-11-05 08:26:14 +05:30
Jonathan Hefner de304819ae
Merge pull request #46425 from bdewater/fix-error-highlight-dark-mode
Make error highlight readable on dark mode
2022-11-04 17:19:24 -05:00
Bart de Water 8cb96a3e04 Make error highlight readable on dark mode 2022-11-04 17:57:46 -04:00
hmbreaux 914a732c21
Add API documentation for Routing#draw
Adding documentation to the API doc for `ActionDispatch::Routing::Mapper::Resources#draw` method,
inspired by the Rails Guide routing section. Also removed extra colon in title.
2022-10-31 21:17:42 -07:00
Jonathan Hefner 7a6bcc6285
Merge pull request #46388 from jonathanhefner/action_view-deprecator
Add `ActionView.deprecator`
2022-10-31 17:04:04 -05:00
Jean Boussier cfa9c9f891 Fix a typo in missing_exact_template.html.erb 2022-10-31 12:11:20 +01:00
Jonathan Hefner b5248aca16 Add ActionView.deprecator
This commit adds `ActionView.deprecator` and replaces all usages of
`ActiveSupport::Deprecation.warn` in `actionview/lib` with
`ActionView.deprecator`.  This commit also replaces a call to Ruby's
`Module#deprecate_constant` with Rails' `DeprecatedConstantProxy`, so
that its deprecation behavior can be configured using
`ActionView.deprecator`.

Additionally, this commit adds `ActionView.deprecator` to
`Rails.application.deprecators` so that it can be configured via
settings such as `config.active_support.report_deprecations`.

This commit also removes a few defunct `assert_deprecated` calls that
were not failing because they were nested in `assert_raises`, and the
raised error prevented checking the deprecation.  (One was mistakenly
kept in d52d773946 when converting
`test_render_file_with_errors` to `test_render_template_with_errors`;
the other two were added in dd9991bac5 but
not removed when the deprecation was completed in
85ecf6e4098601222b604f7c1cbdcb4e49a6d1f0.)
2022-10-30 16:01:39 -05:00
Jonathan Hefner bb96ea70cb
Merge pull request #46366 from jonathanhefner/action_dispatch-deprecator
Add `ActionDispatch.deprecator`
2022-10-29 15:55:20 -05:00
Jean Boussier b3c4ecac2b
Merge pull request #46342 from olivierlacan/docs/view-template
Improve missing template error page
2022-10-28 19:49:22 +02:00