Commit Graph

701 Commits

Author SHA1 Message Date
Grey Baker
9f38a3fb0c Check request.path_parameters encoding at the point they're set
Check for any non-UTF8 characters in path parameters at the point they're
set in `env`. Previously they were checked for when used to get a controller
class, but this meant routes that went directly to a Rack app, or skipped
controller instantiation for some other reason, had to defend against
non-UTF8 characters themselves.
2016-07-14 16:50:49 +01:00
Grey Baker
25c1461766 Don't raise ActionController::UnknownHttpMethod from ActionDispatch::Static
The `ActionDispatch::Static` middleware is used low down in the stack to serve
static assets before doing much processing. Since it's called from so low in
the stack, we don't have access to the request ID at this point, and generally
won't have any exception handling defined (by default `ShowExceptions` is added
to the stack quite a bit higher and relies on logging and request ID).

Before 8f27d6036a
this middleware would ignore unknown HTTP methods, and an exception about these
would be raised higher in the stack. After that commit, however, that exception
will be raised here.

If we want to keep `ActionDispatch::Static` so low in the stack (I think we do)
we should suppress the `ActionController::UnknownHttpMethod` exception here,
and instead let it be raised higher up the stack, once we've had a chance to
define exception handling behaviour.

This PR updates `ActionDispatch::Static` so it passes `Rack::Request` objects to
`ActionDispatch::FileHandler`, which won't raise an
`ActionController::UnknownHttpMethod` error. If an unknown method is
passed, it should exception higher in the stack instead, once we've had a
chance to define exception handling behaviour.`
2016-07-13 17:52:36 +01:00
Grey Baker
fe859a5421 Handle Rack::QueryParser errors in ActionDispatch::ExceptionWrapper
Rack [recently](7e7a389044)
moved the namespace of its `ParameterTypeError` and `InvalidParameterError`
errors. Whilst an alias for the old name was added, the logic in
`ActionDispatch::ExceptionWrapper` was still broken by this change, since it
relies on the class name.

This PR updates `ActionDispatch::ExceptionWrapper` to handle the Rack 2.0
namespaced errors correctly. We no longer need to worry about the old names,
since Rails specifies Rack ~> 2.0.
2016-07-12 16:41:09 +01:00
Rafael Mendonça França
8ecc5ab1d8 Start Rails 5.1 development 🎉 2016-05-10 03:46:56 -03:00
Rafael Mendonça França
fbdcf5221a Preparing for 5.0.0.rc1 release 2016-05-06 16:54:40 -05:00
Prathamesh Sonpatki
bf79bc0395
Release notes: Add PR #24866 to release notes 2016-05-05 23:04:30 -05:00
Rafael Mendonça França
541a51ecf8 Implement helpers proxy in controller instance level
It is a common pattern in the Rails community that when people want to
:xa
use any kind of helper that is defined inside app/helpers they includes
the helper module inside the controller like:

    module UserHelper
      def my_user_helper
        # ...
      end
    end

    class UsersController < ApplicationController
      include UserHelper

      def index
        render inline: my_user_helper
      end
    end

This has problem because the helper can't access anything that is
defined in the view level context class.

Also all public methods of the helper become available in the controller
what can lead to undesirable methods being routed and behaving as
actions.

Also if you helper depends on other helpers or even Action View helpers
you need to include each one of these dependencies in your controller
otherwise your helper is not going to work.

We already have a helpers proxy at controller class level but that proxy
doesn't have access to the instance variables defined in the
controller.

With this new instance level helper proxy users can reuse helpers in the
controller without having to include the modules and with access to
instance variables defined in the controller.

    class UsersController < ApplicationController
      def index
        render inline: helpers.my_user_helper
      end
    end
2016-05-05 16:17:17 -05:00
eileencodes
f7a986012a Prep Rails 5 beta 4 2016-04-27 15:48:47 -05:00
Jeremy Daer
643cac08a3
Merge pull request #23103 from rails/refactor-handling-of-action-default
Refactor handling of :action default in routing
2016-04-24 15:27:46 -07:00
Prathamesh Sonpatki
64b115b451
[ci skip] Remove extra so from the Action Pack CHANGELOG 2016-04-14 09:19:34 +05:30
Rafael Mendonça França
0c21fb361c Merge pull request #24318 from bogdanvlviv/patch-1
extension synonyms yml and yaml
2016-04-12 23:26:45 -03:00
Ryan McCuaig
58c12900b7 it's => its typo 2016-04-04 19:13:57 -07:00
Ryan T. Hosford
f99106805d Fixes #24239
- skip calling helper_method if it's not there: if we don't have helpers, we needn't define one.
  - tests that an api controller can include and use ActionController::Cookies
2016-04-04 08:51:29 -05:00
Jeremy Daer
c1c9c69040 Strong ETag validators
* Introduce `Response#strong_etag=` and `#weak_etag=` and analogous options
  for `fresh_when` and `stale?`. `Response#etag=` sets a weak ETag.

  Strong ETags are desirable when you're serving byte-for-byte identical
  responses that support Range requests, like PDFs or videos (typically
  done by reproxying the response from a backend storage service).
  Also desirable when fronted by some CDNs that support strong ETags
  only, like Akamai.

* No longer strips quotes (`"`) from ETag values before comparing them.
  Quotes are significant, part of the ETag. A quoted ETag and an unquoted
  one are not the same entity.

* Support `If-None-Match: *`. Rarely useful for GET requests; meant
  to provide some optimistic concurrency control for PUT requests.
2016-03-31 18:15:32 -07:00
Rafael Mendonça França
5ed3801481 Deprecate ActionDispatch::ParamsParser instance.
Related with 38d2bf5fd1f3e014f2397898d371c339baa627b1.

cc @tenderlove
2016-03-30 01:17:05 -03:00
Bogdan
3a37c4e371 extension synonyms yml and yaml 2016-03-27 17:20:28 +03:00
Prathamesh Sonpatki
ca9e1e2101 Fix typo in Action Pack changelog [ci skip] 2016-03-25 14:33:00 +05:30
Yves Senn
c94045dc1c guides, sync railties and AP changelogs with 5.0 release notes.
[ci skip]

This updates the 5.0 release notes guide to reflect changes that
happened after beta1 has been released.

I'll sync the other changelogs later today but I'll push this batch to
prevent against cumbersome merge conflicts.
2016-03-22 12:12:39 +01:00
Sean Griffin
3bfda09fa0 Merge pull request #22854 from jcoyne/missing_template
Default rendering behavior if respond_to collector doesn't have a block.
2016-03-11 10:29:10 -07:00
Sean Griffin
5cd2beb013 Add ActionController::Parameters#dig
This method will only be added when used with Ruby 2.3.0 or greater.
This method has the same behavior as `Hash#dig`, except it will convert
hashes to `ActionController::Parameters`, similar to `#[]` and `#fetch`.
2016-03-09 09:49:23 -07:00
Rafael Mendonça França
fe8239e35a Add changelog entry for #24115 [ci skip] 2016-03-09 12:48:56 -03:00
Yves Senn
ab7ad20125 Merge pull request #24086 from yui-knk/do_not_ad_integration_test_class
Prevent not-intended loading of `ActionDispatch::IntegrationTest`
2016-03-07 09:12:18 +01:00
yui-knk
9a642931fb Prevent not-intended loading of ActionDispatch::IntegrationTest
After 9d378747326d26cf1afdac4433ead22967af0984 `ActionDispatch::IntegrationTest`
class is loaded and defined in all Rails environments, not only test but also
production. This is not-intended loading of a class which is only used in
test environment.
To prevent not-intended loading, add `ActiveSupport.run_load_hooks` to
`ActionDispatch::IntegrationTest` with `action_dispatch_integration_test` name
and use it in `ActionMailer`.
2016-03-07 16:48:18 +09:00
Matthew Draper
ee5b621e2f Revert "Merge pull request #20851 from tomprats/indifferent-sessions"
This reverts commit 22db455dbe9c26fe6d723cac0758705d9943ea4b, reversing
changes made to 40be61dfda1e04c3f306022a40370862e3a2ce39.

This finishes off what I meant to do in 6216a092ccfe6422f113db906a52fe8ffdafdbe6.
2016-02-26 04:47:30 +10:30
Justin Coyne
48f140cf74 Render default template if block doesn't render
When a `respond_to` collector doesn't have a response, then a
`:no_content` response should be rendered. This brings the default
rendering behavior introduced by
https://github.com/rails/rails/issues/19036 to controller methods
employing `respond_to`
2016-02-25 07:14:49 -06:00
Godfrey Chan
73b1efc58f Lock down new ImplicitRender behavior for 5.0 RC
1. Conceptually revert #20276

   The feature was implemented for the `responders` gem. In the end,
   they did not need that feature, and have found a better fix (see
   plataformatec/responders#131).

   `ImplicitRender` is the place where Rails specifies our default
   policies for the case where the user did not explicitly tell us
   what to render, essentially describing a set of heuristics. If
   the gem (or the user) knows exactly what they want, they could
   just perform the correct `render` to avoid falling through to
   here, as `responders` did (the user called `respond_with`).

   Reverting the patch allows us to avoid exploding the complexity
   and defining “the fallback for a fallback” policies.

2. `respond_to` and templates are considered exhaustive enumerations

   If the user specified a list of formats/variants in a `respond_to`
   block, anything that is not explicitly included should result
   in an `UnknownFormat` error (which is then caught upstream to
   mean “406 Not Acceptable” by default). This is already how it
   works before this commit.

   Same goes for templates – if the user defined a set of templates
   (usually in the file system), that set is now considered exhaustive,
   which means that “missing” templates are considered `UnknownFormat`
   errors (406).

3. To keep API endpoints simple, the implicit render behavior for
   actions with no templates defined at all (regardless of formats,
   locales, variants, etc) are defaulted to “204 No Content”. This
   is a strictly narrower version of the feature landed in #19036 and
   #19377.

4. To avoid confusion when interacting in the browser, these actions
   will raise an `UnknownFormat` error for “interactive” requests
   instead. (The precise definition of “interactive” requests might
   change – the spirit here is to give helpful messages and avoid
   confusions.)

Closes #20666, #23062, #23077, #23564

[Godfrey Chan, Jon Moss, Kasper Timm Hansen, Mike Clark, Matthew Draper]
2016-02-25 01:19:49 -08:00
eileencodes
dbfa8fdfc2 Preparing for 5.0.0.beta3 release
Adds changelog headers for beta3 release
2016-02-24 11:14:40 -05:00
Rafael Mendonça França
53c19c5024 No need CHANGELOG entry for #23849.
It is not a released feature so we don't need to add changelogs to
changes on it.

[ci skip]
2016-02-24 10:29:14 -03:00
Prathamesh Sonpatki
5f59c10471 Show permitted flag in the output of AC::Parameters#inspect
- Fixes #23822.
2016-02-24 13:55:37 +05:30
Rafael Mendonça França
22db455dbe Merge pull request #20851 from tomprats/indifferent-sessions
Give Sessions Indifferent Access
2016-02-24 00:22:04 -03:00
Andrew White
8ca8a2d773 Refactor handling of :action default in routing
The longstanding convention in Rails is that if the :action parameter
is missing or nil then it defaults to 'index'. Up until Rails 5.0.0.beta1
this was handled slightly differently than other routing defaults by
deleting it from the route options and adding it to the recall parameters.

With the recent focus of removing unnecessary duplications this has
exposed a problem in this strategy - we are now mutating the request's
path parameters and causing problems for later url generation. This will
typically affect url_for rather a named url helper since the latter
explicitly pass :controller, :action, etc.

The fix is to add a default for :action in the route class if the path
contains an :action segment and no default is passed. This change also
revealed an issue with the parameterized part expiry in that it doesn't
follow a right to left order - as soon as a dynamic segment is required
then all other segments become required.

Fixes #23019.
2016-02-16 09:52:26 +00:00
Mehmet Emin İNAÇ
ff8bdafec4 application/gzip added as default mime type into mime type list 2016-02-13 19:25:28 +02:00
Kasper Timm Hansen
da1fbb9a00 Add fixes accidentally removed.
Yesterday, when improving how `parsed_body` extracted a parser I wrote
77bbf1e. Then I thought that was too many changes in one commit
and broke it up locally... or so I thought.

When pushed the extra commits removed the changes! Wups!

In shame, lob those changes together here:

  * 3b94c38 which meant to fix the CHANGELOG syntax error.
  * 5007df5 which meant to mention `parsed_body` in the docs.
  * 036a7a0 which meant to memoize the `parsed_body`.
2016-02-12 20:13:48 +01:00
Kasper Timm Hansen
354fb73ff2 Flesh out request encoding + response parsing changelog entry.
Add more info about the APIs added and how they work.

Use string keys when comparing the parsed response, like how JSON would
be parsed.
2016-02-12 20:13:48 +01:00
Gaurav Sharma
33e202d3ae use rails instead of rake
since starting with Rails 5.x(beta) we prefer to use rails as the replacement of rake commands, may be change log will be the same
2016-02-12 23:12:56 +05:30
Vipul A M
ef2a8c2391 - Fixed and removed long arguments to rake routes
- Fixed related documentation and usage all around

Fixes #23561
2016-02-12 14:35:57 +05:30
Kasper Timm Hansen
c85b17773e Add request encoding and response parsing to changelog.
Forgot to add this in the original pull request. No biggie, just show
some examples.
2016-02-10 22:05:08 +01:00
David Heinemeier Hansson
7e35cb2987 Add SVG as a default mime type 2016-02-07 15:34:13 +01:00
Kang-Kyu Lee
c4ac23bfa6 Update CHANGELOG.md
fix indentation to show it as code
2016-02-01 14:21:34 -08:00
Rafael Mendonça França
60b040e362 Add some Action Cable CHANGELOG entries
And improve changelongs.

[ci skip]
2016-02-01 19:57:50 -02:00
Sean Griffin
49f6ce63f3 Preparing for Rails 5.0.0.beta2 2016-02-01 14:37:52 -07:00
Vipul A M
8a436fdd98 Add options for rake routes task
Add two options: `-c` and `-g`.
`-g` option returns the urls name, verb and path fields that match the pattern.
`-c` option returns the urls for specific controller.

Fixes #18902, and Fixes #20420

[Anton Davydov & Vipul A M]
2016-02-02 00:27:30 +05:30
Tom Prats
82dc8266dd Update session to have indifferent access 2016-01-29 17:22:05 -05:00
Vipul A M
48c03c59c3 rm changelog for unreleased changes fixes
Based on https://github.com/rails/rails/pull/23167/files#r50507317

[ci skip]
2016-01-22 12:43:03 +05:30
Jon Moss
627f736cc0 Fix ActionController::Parameters#== bug
See bug #21032.
2016-01-21 17:28:18 -05:00
abhishek
e362c31b34 Response etags to always be weak: Prefixed W/ to value returned by ActionDispatch::Http::Cache::Response#etag= such that etags set in fresh_when and stale? are weak. For #17556. 2016-01-20 07:57:30 +05:30
Vipul A M
ee14fbe4ee Pass through AP CHANGELOG [ci skip] 2016-01-18 12:05:23 +05:30
Yves Senn
f5ab4055b9 docs, formatting pass over changelogs. [ci skip] 2016-01-13 10:19:55 +01:00
Sean Collins
a4032ca072 Add both HTTP Response Code and Type to assertion messages
Also, refactor logic to convert between symbol and response code,
via the AssertionResponse class
2016-01-12 13:09:00 -07:00
Prathamesh Sonpatki
4824971f36 Fix typo in ActionPack CHANGELOG [ci skip] 2016-01-08 08:31:08 +05:30