Commit Graph

14949 Commits

Author SHA1 Message Date
Eugene Kenny
173e7ef16d
Merge pull request #41067 from eugeneius/relative_file_fixture_path
Fix fixture_file_upload deprecation with relative file_fixture_path
2021-01-18 08:16:11 +00:00
John Hawthorn
c933b06317 Fix issue routing with optional parts of a segment
In our recent optimizations to route matching performance we introduced
an issue with routes that had an optional segment which wasn't separated
by a "." or "/".
2021-01-12 14:30:59 -08:00
Eugene Kenny
a7b548a0e9 Fix fixture_file_upload deprecation with relative file_fixture_path
When using `Pathname#relative_path_from`, the receiver and the argument
must either both be absolute or both be relative:

https://ruby-doc.org/stdlib-2.7.2/libdoc/pathname/rdoc/Pathname.html#method-i-relative_path_from

> If self is absolute, then base_directory must be absolute too.
>
> If self is relative, then base_directory must be relative too.

If `file_fixture_path` is a relative path and `fixture_path` is an
absolute path, this line would previously raise an ArgumentError.
2021-01-09 19:14:12 +00:00
Theo Julienne
16a80882f9 actionpack: Improve performance by allowing routes with custom regexes in the FSM.
The FSM used to find matching routes was previously limited to patterns
that contained parameters with the default regexp / no constraints. In
large route sets where many parameters are constrained by custom regexp,
these routes all fall back on a slow linear search over the route list.

These custom regexes were not previously able to be included in the FSM
because it transitioned between nodes using only fragments of the URI,
or path separators [/.?], but a custom regex may cross a path separator
boundary. To work around this, the TransitionTable is improved to
support remembering a point within the matching string that we started,
and continuing to attempt to match from that point up to the end of each
token. Only parameters not on a path separator boundary must still match
with a linear search after this change (e.g. `/foo-:bar/`).

This results in performance for constrainted routes that matches that of
ones using the default regexp.

Benchmark:
https://gist.github.com/theojulienne/e91fc338d180e1710e29c81a5d701fab

Before:
```
Calculating -------------------------------------
    without params      6.466k (±12.7%) i/s -     31.648k in   5.009453s
params without constraints
                        5.867k (±12.9%) i/s -     28.842k in   5.032637s
params with constraints
                      909.661  (± 7.9%) i/s -      4.536k in   5.023534s
```

After:
```
Calculating -------------------------------------
    without params      6.387k (±11.9%) i/s -     31.728k in   5.068939s
params without constraints
                        5.824k (±13.2%) i/s -     28.650k in   5.043701s
params with constraints
                        5.406k (±11.7%) i/s -     26.931k in   5.076412s
```

For github.com which has many constrainted parameters, a random sampling
of 10 URL patterns can be matched approximately 2-4x faster than before.

This commit fixes symbols as constrains as tested in
6ab985da28
2021-01-06 09:54:44 +11:00
Rafael Mendonça França
6ab985da28
Revert "actionpack: Improve performance by allowing routes with custom regexes in the FSM."
This reverts commit c67c764aabb7aaabe4034245481842b0df1480bc.

This broken constaints using symbols as values. Test added on this
commit.
2021-01-05 22:21:53 +00:00
Theo Julienne
c67c764aab actionpack: Improve performance by allowing routes with custom regexes in the FSM.
The FSM used to find matching routes was previously limited to patterns
that contained parameters with the default regexp / no constraints. In
large route sets where many parameters are constrained by custom regexp,
these routes all fall back on a slow linear search over the route list.

These custom regexes were not previously able to be included in the FSM
because it transitioned between nodes using only fragments of the URI,
or path separators [/.?], but a custom regex may cross a path separator
boundary. To work around this, the TransitionTable is improved to
support remembering a point within the matching string that we started,
and continuing to attempt to match from that point up to the end of each
token. Only parameters not on a path separator boundary must still match
with a linear search after this change (e.g. `/foo-:bar/`).

This results in performance for constrainted routes that matches that of
ones using the default regexp.

Benchmark:
https://gist.github.com/theojulienne/e91fc338d180e1710e29c81a5d701fab

Before:
```
Calculating -------------------------------------
    without params      6.466k (±12.7%) i/s -     31.648k in   5.009453s
params without constraints
                        5.867k (±12.9%) i/s -     28.842k in   5.032637s
params with constraints
                      909.661  (± 7.9%) i/s -      4.536k in   5.023534s
```

After:
```
Calculating -------------------------------------
    without params      6.387k (±11.9%) i/s -     31.728k in   5.068939s
params without constraints
                        5.824k (±13.2%) i/s -     28.650k in   5.043701s
params with constraints
                        5.406k (±11.7%) i/s -     26.931k in   5.076412s
```

For github.com which has many constrainted parameters, a random sampling
of 10 URL patterns can be matched approximately 2-4x faster than before.
2021-01-05 08:11:43 +11:00
Ryuta Kamizono
2b0b5a75c0 Bump license years to 2021 [ci skip] 2021-01-01 12:21:20 +09:00
Rafael França
e0d3c6cb4d
Merge pull request #40960 from abhaynikam/40956-route-table-dark-mode
Fixes the route table CSS for dark mode
2020-12-28 23:08:46 -05:00
Rafael Mendonça França
03156c829d
Support selenium-webdriver 4
* Use public API to add argument to the selenium driver.

  While `args` is also public API it doesn't know how to handle if no
  argument is being set yet in Selenium 4.

* Fix assertions to match return on Selenium 4
2020-12-29 02:36:01 +00:00
Rafael Mendonça França
72d30056a4
No need to freeze constants 2020-12-28 22:21:18 +00:00
Abhay Nikam
4bc2592ba9 Fixes the route table CSS for dark mode 2020-12-28 09:52:36 -08:00
Alex Robbin
ea40dd3328
quietly handle unknown HTTP methods in Action Dispatch SSL middleware
Because `ActionDispatch::SSL` is included higher up in the middleware stack than `ActionDispatch::ShowExceptions`, it should ideally not be raising any exceptions.

In this case, `ActionDispatch::Request#{get,head}?` are called, which check if the HTTP method is valid. If it isn't, `ActionController::UnknownHttpMethod` is raised. Instead of calling the Rack-provided predicate methods, we leverage `raw_request_method`.
2020-12-28 07:27:50 -05:00
Jan Klimo
0c1028f4bb Fix nil translation key lookup in controllers 2020-12-22 21:17:51 +07:00
Alex Robbin
cb23580684
change request method to a GET when passing failed requests to config.exceptions_app
Similar to #38998 (fixed in #40246), HTTP method validation occurring whenever methods are called on `ActionDispatch::Request` can cause some weird unintended consequences. For example, if `config.exceptions_app = self.routes`, you get an exception raised via the `ActionDispatch::ShowExceptions` middleware failsafe:

```
Started TEST "/" for 127.0.0.1 at 2020-11-05 15:40:31 -0500
   (1.0ms)  SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
TEST, accepted HTTP methods are OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT, PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK, VERSION-CONTROL, REPORT, CHECKOUT, CHECKIN, UNCHECKOUT, MKWORKSPACE, UPDATE, LABEL, MERGE, BASELINE-CONTROL, MKACTIVITY, ORDERPATCH, ACL, SEARCH, MKCALENDAR, and PATCH excluded from capture: DSN not set

ActionController::UnknownHttpMethod (TEST, accepted HTTP methods are OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT, PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK, VERSION-CONTROL, REPORT, CHECKOUT, CHECKIN, UNCHECKOUT, MKWORKSPACE, UPDATE, LABEL, MERGE, BASELINE-CONTROL, MKACTIVITY, ORDERPATCH, ACL, SEARCH, MKCALENDAR, and PATCH):

actionpack (6.0.3.4) lib/action_dispatch/http/request.rb:431:in `check_method'
actionpack (6.0.3.4) lib/action_dispatch/http/request.rb:143:in `request_method'
rack (2.2.3) lib/rack/request.rb:187:in `head?'
actionpack (6.0.3.4) lib/action_dispatch/journey/router.rb:113:in `find_routes'
actionpack (6.0.3.4) lib/action_dispatch/journey/router.rb:32:in `serve'
actionpack (6.0.3.4) lib/action_dispatch/routing/route_set.rb:834:in `call'
Error during failsafe response: TEST, accepted HTTP methods are OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT, PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK, VERSION-CONTROL, REPORT, CHECKOUT, CHECKIN, UNCHECKOUT, MKWORKSPACE, UPDATE, LABEL, MERGE, BASELINE-CONTROL, MKACTIVITY, ORDERPATCH, ACL, SEARCH, MKCALENDAR, and PATCH
  /usr/local/var/rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.0.3.4/lib/action_dispatch/http/request.rb:431:in `check_method'
  /usr/local/var/rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.0.3.4/lib/action_dispatch/http/request.rb:143:in `request_method'
  /usr/local/var/rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rack-2.2.3/lib/rack/request.rb:187:in `head?'
  /usr/local/var/rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.0.3.4/lib/action_dispatch/journey/router.rb:113:in `find_routes'
  /usr/local/var/rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.0.3.4/lib/action_dispatch/journey/router.rb:32:in `serve'
  /usr/local/var/rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.0.3.4/lib/action_dispatch/routing/route_set.rb:834:in `call'
  /usr/local/var/rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.0.3.4/lib/action_dispatch/middleware/show_exceptions.rb:50:in `render_exception'
  /usr/local/var/rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.0.3.4/lib/action_dispatch/middleware/show_exceptions.rb:36:in `rescue in call'
  /usr/local/var/rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.0.3.4/lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
  # ...
```

Now, to prevent the redundant exception, we overwrite `request_method` before passing `env` down to `config.exceptions_app`. `action_dispatch.original_request_method` is set to keep the original request method available for inspection.
2020-12-16 20:48:09 -05:00
T.J. Schuck
fe861bbdd2 Fix code formatting
The `+` is insufficient for the parens inside — needs the full `<tt>` treatment.

[ci skip]
2020-12-15 10:54:26 -05:00
KapilSachdev
a908d06c85
feat(rubocop): Add Style/RedundantRegexpEscape
- This cop will help in removing unnecessary escaping inside Regexp literals.
2020-12-08 18:57:09 +00:00
Rafael Mendonça França
59f7f5889e
Start Rails 6.2 development 🎉 2020-12-03 01:35:29 +00:00
Rafael França
89414f561a
Merge pull request #40045 from sandip-mane/40041-hosts-case-fix
Adds a fix to whitelist hostnames with case-insensitive matching
2020-11-30 18:44:12 -05:00
Akira Matsuda
46c22fc1bf Simply require rather than autoload + immediately load 2020-11-26 21:15:51 +09:00
Akira Matsuda
22990028a6 ActionDispatch::Assertions uses no AS::Concern feature since ddc584e89eaf6845f8cd72bcafce5035c9893dbb 2020-11-26 19:20:21 +09:00
Akira Matsuda
d331e6d7dc AC::Streaming uses no AS::Concern feature since 7da88c5b297486cd90696133d287be7d60d65218 2020-11-26 01:37:55 +09:00
Akira Matsuda
ac7d112430 AC::Testing uses no AS::Concern feature since 879d540adc34603f0fd1ac1a44763598e9ccc551 2020-11-26 01:37:55 +09:00
Akira Matsuda
ec0050edf3 Fix SyntaxError in the API doc
[ci skip]
2020-11-25 23:20:56 +09:00
David Heinemeier Hansson
5636604b45 Fix CHANGELOG reference to old method name 2020-11-24 11:00:56 +01:00
David Heinemeier Hansson
1535af1c31
Get rid of the cumbersome fallback_location keyword argument for redirect_back (#40671) 2020-11-24 10:17:11 +01:00
Petrik
2e079154a8 Use Feature-Policy header name for now
In 90e710d7672b928ce6bb3ec05f8f2c05338be6c9 the FeaturePolicy middleware
was renamed to PermissionsPolicy as this will be new name of the header
as used by browsers.
The Permissions-Policy header requires a different implementation and
isn't yet supported by all browsers. To avoid having to rename the
middleware in the future, we keep the new name for the Middleware, but
use the old implementation and header name.
2020-11-19 16:08:09 +01:00
Ryuta Kamizono
151bce17b6 Rename s/feature_policy/permissions_policy/ in the CHANGELOG [ci skip] 2020-11-19 11:35:14 +09:00
Julien Grillot
90e710d767 Rename HTTP Feature Policy to Permissions Policy
HTTP Feature-Policy has been renamed to Permissions-Policy:
* Original issue: https://github.com/w3c/webappsec-permissions-policy/issues/359
* PR: https://github.com/w3c/webappsec-permissions-policy/pull/379
* Doc: https://w3c.github.io/webappsec-permissions-policy/

Mozilla documentation has been updated on July 2020:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Feature-Policy
2020-11-14 17:31:58 +01:00
Rafael França
a538e4dee5
Merge pull request #40567 from hahmed/ha/formatted-error-messages
Display exception messages using simple_format
2020-11-09 18:11:06 -05:00
Jonathan Hefner
2e53730d62 Document ActionController::Cookies#cookies [ci-skip]
There are several `cookies` methods that appear when searching the API
documentation, but none of them are the method commonly used in
controllers.

This makes Action Controller's `cookies` method appear in the search
results, and makes the accompanying `ActionDispatch::Cookies`
documentation more discoverable.
2020-11-09 16:38:42 -06:00
Haroon Ahmed
93f0cebd1d Display exception messages using simple_format for a better and clearer
exception message.
2020-11-09 21:48:24 +00:00
Rafael Mendonça França
8389f9902c
Preparing for 6.1.0.rc1 release 2020-11-02 21:12:47 +00:00
Chris Bisnett
1f767407cb Add request exclusion to Host Authorization
In the same way that requests may need to be excluded from forced SSL,
requests may also need to be excluded from the Host Authorization
checks. By providing this additional flexibility more applications
will be able to enable Host Authorization while excluding requests
that may not conform. For example, AWS Classic Load Balancers don't
provide a Host header and cannot be configured to send one. This means
that Host Authorization must be disabled to use the health check
provided by the load balancer. This change will allow an application
to exclude the health check requests from the Host Authorization
requirements.

I've modified the `ActionDispatch::HostAuthorization` middleware to
accept arguments in a similar way to `ActionDispatch::SSL`. The hosts
configuration setting still exists separately as does the
hosts_response_app but I've tried to group the Host Authorization
settings like the ssl_options. It may make sense to deprecate the
global hosts_response_app if it's only used as part of the Host
Authorization failure response. I've also updated the existing tests
as the method signature changed and added new tests to verify the
exclusion functionality.
2020-11-02 20:16:29 +00:00
Rafael França
0300aa802a
Merge pull request #40504 from tbrisker/paramobjects
Reduce object allocations in param wrapping
2020-11-02 12:52:24 -05:00
Tomer Brisker
1bc7cce8fe
Reduce object allocations in param wrapping
When wrapping parameters, `_extract_parameters` is called twice for
every request. In most cases, both the `include` and `exclude` options
will be empty. In that case, we can use a logical check to save
allocation of an empty array and another allocation of a new array
concatenating the empty array with the hard-coded `EXCLUDE_PARAMETERS`.
The result is 4 array allocations less per request when wrapping is
enabled and `exclude` is not set.
2020-11-01 15:07:03 +02:00
Eugene Kenny
de0f59f1ce
Merge pull request #38261 from vipulnsward/wrapper-support-alias-attrs
Adds support to wrap aliased attributed in object hash in params wrapper
2020-11-01 12:42:37 +00:00
Rafael Mendonça França
a09b04e637
Fix tests with Ruby 3 2020-10-30 02:20:04 +00:00
Ryuta Kamizono
8512213a39 Fix deprecation will be removed version s/Rails 6.1/Rails 6.2/ 2020-10-30 10:11:29 +09:00
Jonathan Hefner
614e813161
Disentangle Action Text from ApplicationController
This commit allows Action Text to be used without having an
ApplicationController defined.  In doing so, it also fixes Action Text
attachments to render the correct URL host in mailers.

It also avoids allocating an ActionController::Renderer per request.

Fixes #37183.
Fixes #35578.
Fixes #36963.
Closes #38714.

Co-authored-by: Jeremy Daer <jeremydaer@gmail.com>
2020-10-30 01:01:42 +00:00
Rafael Mendonça França
5087d00153
Always ask for a header argument in ResquestId middleware 2020-10-30 00:41:59 +00:00
Arlston Fernandes
2711dcc9a6
Customise the header name for ActionDispatch::RequestId
by setting `config.action_dispatch.request_id_header` to the desired value

* Ensure HTTP_X_REQUEST_ID presence to maintain compatiblility

* Use req.headers[] to fetch header rather than ENV methods

* Update configuration doc to match existing descriptions

* Add changelog entry for action_dispatch.request_id_header
2020-10-30 00:31:09 +00:00
Rafael Mendonça França
64efe502f3
Change ActionDispatch::Response#content_type to return the full Content-Type header
And deprecate the config to keep the previous behavior.
2020-10-30 00:25:49 +00:00
Rafael Mendonça França
cd0c99c991
Make the arguments of ActionView::Base#initialize required 2020-10-30 00:25:24 +00:00
Rafael Mendonça França
d52d773946
Remove deprecated support to passing relative paths to render file: 2020-10-30 00:25:14 +00:00
Rafael Mendonça França
3e2552db89
Remove deprecated ActionDispatch::Http::ParameterFilter 2020-10-30 00:25:10 +00:00
Rafael França
f8d7ab5f3c
Merge pull request #39705 from Shopify/actioncontroller-testcase-parameters-fix
Fix the ActionController::TestCase#process parameters serialization
2020-10-29 17:43:32 -04:00
John Hawthorn
e3130f1b84
Revert "Raise when calling render with invalid options" 2020-10-29 13:49:30 -07:00
John Hawthorn
e53e2a006b Validate arguments to render calls 2020-10-28 19:30:48 -07:00
Rafael Mendonça França
7cb4513466
Copy-edit the documentation [ci skip] 2020-10-27 18:13:40 +00:00
HParker
9a2f63acbc avoid calling custom_encoding_for when unused
if the action does not use a custom encoding, then we can skip checking if we need to fix the encoding on any of the parameters.

Instead of asking the controller about each of the parameters, we can ask the controller to tell us what params to convert once. If the controller returns nothing, we have no work to do.
2020-10-27 10:42:41 -07:00