Commit Graph

540 Commits

Author SHA1 Message Date
Arthur Neves
86433b8d5f
Add CHANGELOG for #14886
Also cleanup test a bit

[related #14886]
[related #14743]
2014-07-18 13:27:43 -04:00
Grey Baker
f49d20ef36 Stash original path in ShowExceptions middleware
`ActionDispatch::ShowExceptions` overwrites `PATH_INFO` with the status code
for the exception defined in `ExceptionWrapper`, so the path the user was
visiting when an exception occurred was not previously available to any custom
exceptions_app.

The original `PATH_INFO` is now stashed in
`env["action_dispatch.original_path"]`.
2014-07-14 11:55:44 +01:00
Agis-
e67f001e7c Use #bytesize instead of #size when checking for cookie overflow
Although the cookie values happens to be ASCII strings because they are
Base64 encoded, it is semantically incorrect to check for the number of the
characters in the cookie, when we actually want to check for the number of the
bytes it consists of.

Furthermore it is unecessary coupling with the current implementation that
uses Base64 for encoding the values.
2014-07-11 13:24:49 +03:00
Godfrey Chan
00aae7cb38 Synced 4.2 release notes with the latest commits.
Also reordered some of the items to put newer ones on top (same order as
CHANGELOGs), which makes it easier to diff while we are still working on it.
2014-07-11 02:16:57 -07:00
Godfrey Chan
013c74d645 Removed single space padding from empty response body.
`render nothing: true` or rendering a `nil` body no longer add a single
space to the response body.

The old behavior was added as a workaround for a bug in an early version of
Safari, where the HTTP headers are not returned correctly if the response
body has a 0-length. This is been fixed since and the workaround is no
longer necessary.

Use `render body: ' '` if the old behavior is desired.
2014-07-10 16:33:22 -07:00
Rafael Mendonça França
3229eda00c Merge pull request #11218 from kaspth/loofah-integration
Loofah-integration

Conflicts:
	actionpack/CHANGELOG.md
	actionview/CHANGELOG.md
2014-07-10 16:52:00 -03:00
Aaron Patterson
93fb4c1e62 Merge branch 'rosetta_flash' of https://github.com/gcampbell/rails into gcampbell-rosetta_flash
* 'rosetta_flash' of https://github.com/gcampbell/rails:
  Address CVE-2014-4671 (JSONP Flash exploit)

Conflicts:
	actionpack/CHANGELOG.md
2014-07-10 10:20:16 -07:00
Karl Entwistle
8a29713134 Force encoding of US-ASCII to UTF-8 in unescape_uri.
Because URI paths may contain non US-ASCII characters we need to force
the encoding of any unescaped URIs to UTF-8 if they are US-ASCII.
This essentially replicates the functionality of the monkey patch to
URI.parser.unescape in active_support/core_ext/uri.rb.

Fixes #16104.
2014-07-10 10:02:11 +01:00
Greg Campbell
4003a5bd76 Address CVE-2014-4671 (JSONP Flash exploit)
Adds a comment before JSONP callbacks. See
http://miki.it/blog/2014/7/8/abusing-jsonp-with-rosetta-flash/ for more
details on the exploit in question.
2014-07-09 11:37:19 -07:00
Seb Jacobs
e972d34120 Generate shallow paths for all children of shallow resources.
Prior to this commit shallow resources would only generate paths for
non-direct children (with a nested depth greater than 1).

Take the following routes file.

    resources :blogs do
      resources :posts, shallow: true do
        resources :comments do
          resources :tags
        end
      end
    end

This would generate shallow paths for `tags` nested under `posts`,
e.g `/posts/:id/tags/`, however it would not generate shallow paths
for `comments` nested under `posts`, e.g `/posts/:id/comments/new`.

This commit changes the behaviour of the route mapper so that it
generate paths for direct children of shallow resources, for example
if you take the previous routes file, this will now generate
shallow paths for `comments` nested under `posts`, .e.g
`posts/:id/comments/new`.

This was the behaviour in Rails `4.0.4` however this was broken in
@jcoglan's fix for another routes related issue[1].

This also fixes an issue[2] reported by @smdern.

[1] https://github.com/rails/rails/commit/d0e5963
[2] https://github.com/rails/rails/issues/15783
2014-07-06 08:52:32 +01:00
Lucas Mazza
b00b638b95 Change the JSON renderer to enforce the 'JS' Content Type
The controller can set the response format as 'JSON' before the renderer code be
evaluated, so we must replace it when necessary.

Fixes #15081
2014-07-02 20:02:00 -03:00
Rafael Mendonça França
ebdedaec32 Merge pull request #15933 from rafael/master
Add always permitted parameters as a configurable option.

[Rafael Mendonça França + Gary S. Weaver]
2014-06-27 18:16:52 -03:00
Timm
7cd2eb516e Added deprecation notice to actionpack changelog. 2014-06-16 21:04:14 +02:00
Larry Lv
4a9d4c85c3 Fix request's path_info when a rack app mounted at '/'.
Fixes issue #15511.
2014-06-14 04:57:33 +08:00
Matthew Draper
497def80b5 Merge pull request #15692 from sromano/falseClass
ActionController::Parameters#require now accepts FalseClass values
2014-06-14 06:14:19 +09:30
Sergio Romano
540d153531 ActionController::Parameters#require now accepts FalseClass values
Fixes #15685.
2014-06-13 14:42:38 -03:00
Larry Lv
fdb1059795 Fix parsed token value with header Authorization token=. 2014-06-13 16:29:15 +08:00
Matthew Draper
6a89850dfe Handle client disconnect during live streaming
.. even when the producer is blocked for a write.
2014-06-08 07:21:14 +09:30
Rafael Mendonça França
489a8f2a44 Partially revert deprecation of *_filter
We are going to deprecate only on Rails 5 to make easier plugin
maintainers support different Rails versions. Right now we are only
discouraging their usage.

This reverts commit 6c5f43bab8206747a8591435b2aa0ff7051ad3de.

Conflicts:
	actionpack/CHANGELOG.md
2014-06-03 19:53:28 -03:00
Aaron Patterson
cc26b6b7bc Routes specifying 'to:' must be a string that contains a "#" or a rack
application.  Use of a symbol should be replaced with `action: symbol`.
Use of a string without a "#" should be replaced with `controller: string`.
2014-06-03 14:05:42 -07:00
Zachary Scott
84d956e3f4 Missing period from AP/CHANGELOG [ci skip] 2014-05-31 11:21:56 -07:00
Rafael Mendonça França
6c5f43bab8 Deprecate all *_filter callbacks in favor of *_action callbacks
This is the continuation of the work started at
9d62e04838f01f5589fa50b0baa480d60c815e2c
2014-05-27 19:10:14 -03:00
Rafael Mendonça França
ade105be40 Merge pull request #14986 from dlangevin/trailing-slash-url-generation
Fixes URL generation with trailing_slash: true

Conflicts:
	actionpack/lib/action_dispatch/http/url.rb
2014-05-24 12:41:28 -03:00
Zachary Scott
1d7b3fa84c Future port c8ddb61 2014-05-23 14:45:21 -07:00
Dan Langevin
82b4d879bf Fixes URL generation with trailing_slash: true
URL generation with trailing_slash: true was adding a trailing slash
after .:format

    Routes.draw do
      resources :bars
    end

    bars_url(trailing_slash: true, format: 'json')
      # => /bars.json/

This commit removes that extra trailing slash
2014-05-22 16:03:52 -04:00
Guo Xiang Tan
4fd144dd4b Form full URI as string to be parsed in Rack::Test.
There are performance gains to be made by avoiding URI setter methods.
2014-05-21 23:17:17 -07:00
Rafael Mendonça França
16a8a68b7e Merge pull request #15118 from khelben/head_with_status_action_stack_level_too_deep
fixes stack level too deep exception on action named 'status' rendering 'head :ok'
2014-05-15 16:18:37 -03:00
Christiaan Van den Poel
20fece1491 fixes stack level too deep exception on action named 'status' returning 'head :ok' 2014-05-15 21:14:46 +02:00
Rafael Mendonça França
cf50bbd68c Merge pull request #15121 from skarpesh/rfc4791-methods
Add RFC 4791 MKCALENDAR method
2014-05-15 14:37:35 -03:00
kasper
42728c70ee Add RFC4791 MKCALENDAR method 2014-05-15 17:41:37 +03:00
Rafael Mendonça França
f2bff250a0 Merge pull request #14137 from dasch/better-fragment-cache-instrumentation
Add controller and action name to the fragment caching instrumentation payload

Conflicts:
	actionpack/CHANGELOG.md
2014-05-14 20:04:43 -03:00
Andrew White
2378f69e69 Always use the provided port for protocol relative urls
There may be situations where you need to tunnel SSL connections over
port 80 so we shouldn't remove it if it has been explicitly provided.
2014-05-11 12:59:37 +01:00
Daniel Schierbeck
92fbbf67e3 Add controller and action name to the instrumentation payload 2014-05-10 09:35:29 +00:00
Tom Kadwill
7d5a858e5c Moved 'params[request_forgery_protection_token]' into its own method and improved tests. 2014-05-06 14:58:30 +01:00
Rafael Mendonça França
e918516d2f Improve CHANGELOG entry 2014-05-04 18:47:29 -03:00
Rafael Mendonça França
95ab4fd6b7 Merge pull request #11166 from xavier/callable_constraint_verification
Callable route constraint verification

Conflicts:
	actionpack/CHANGELOG.md
2014-05-04 18:42:20 -03:00
Rafael Mendonça França
b638c1a0b3 Merge pull request #12651 from cespare/ipv6-remote-ip-fixes
Make remote_ip detection properly handle private IPv6 addresses

Conflicts:
	actionpack/CHANGELOG.md
2014-05-01 14:43:14 -03:00
Godfrey Chan
2a412b3d6f Fixed an issue with migrating legacy json cookies.
Previously, the `VerifyAndUpgradeLegacySignedMessage` assumes all incoming
cookies are marshal-encoded. This is not the case when `secret_token` is
used in conjunction with the `:json` or `:hybrid` serializer.

In those case, when upgrading to use `secret_key_base`, this would cause a
`TypeError: incompatible marshal file format` and a 500 error for the user.

Fixes #14774.

*Godfrey Chan*
2014-04-23 12:32:14 -05:00
Andrew White
5460591f02 Make URL escaping more consistent
1. Escape '%' characters in URLs - only unescaped data
   should be passed to URL helpers

2. Add an `escape_segment` helper to `Router::Utils`
   that escapes '/' characters

3. Use `escape_segment` rather than `escape_fragment`
   in optimized URL generation

4. Use `escape_segment` rather than `escape_path`
   in URL generation

For point 4 there are two exceptions. Firstly, when a route uses wildcard
segments (e.g. *foo) then we use `escape_path` as the value may contain '/'
characters. This means that wildcard routes can't be optimized. Secondly,
if a `:controller` segment is used in the path then this uses `escape_path`
as the controller may be namespaced.

Fixes #14629, #14636 and #14070.
2014-04-20 10:11:38 +01:00
Rafael Mendonça França
c91a531ff3 Add CHANGELOG entry for #14755 [ci skip] 2014-04-17 14:50:52 -03:00
Rafael Mendonça França
4d21e496e1 Return null type format when format is not know
When requesting a controller with the following code with a unknown format:

    def my_action
      respond_to do |format|
        format.json { head :ok }
        format.any { render text: 'Default response' }
      end
    end

we should render the default response instead of raising ActionController::UnknownFormat

Fixes #14462

Conflicts:
	actionpack/CHANGELOG.md
	actionpack/test/controller/mime/respond_with_test.rb

Conflicts:
	actionpack/CHANGELOG.md
2014-04-14 17:10:11 -03:00
Rafael Mendonça França
f1a4f0a494 Add CHANGELOG entry for #14619 [ci skip] 2014-04-11 11:27:41 -03:00
Andrew White
e10f26f9e9 Only make deeply nested routes shallow when parent is shallow
Since `:shallow` may be set at any point in the resource nesting we should
only make the new and collection routes shallow when the parent is shallow.

This is a bit of a hack but until the mapper is refactored to an object graph
instead of a hash of merged values it's the best we can do.

Fixes #14684.
2014-04-11 10:20:54 +01:00
Boris Kuznetsov
6af07c27ae Append link to bad code to backtrace when exception is SyntaxError 2014-03-27 00:36:59 +04:00
Vishal Lal
0ebae1dbc5 Swapped parameters of assert_equal in assert_select 2014-03-22 22:58:37 +00:00
Andrew White
bb0518891c Use nested_scope? not shallow? to determine whether to copy options
The method `shallow?` returns false if the parent resource is a singleton so
we need to check if we're not inside a nested scope before copying the :path
and :as options to their shallow equivalents.

Fixes #14388.
2014-03-16 09:35:35 +00:00
Carlos Antonio da Silva
45efd0ebf7 Move changelog entry to the top, highlight module name [ci skip] 2014-03-08 18:20:45 -03:00
John Barton (joho)
67584c6ae3 Make CSRF failure logging optional/configurable.
Added the log_warning_on_csrf_failure option to ActionController::RequestForgeryProtection
which is on by default.
2014-03-05 11:31:57 +11:00
Tony Wooster
a351149e80 Fix controller test not resetting @_url_options
Commit 4f2cd3e9 introduced a bug by reordering the call to
`@controller.recycle!` above the call to `build_request_uri`. The
impact of this was that the `@_url_options` cache ends up not being
reset between building a request URI (occurring within the test
controller) and the firing of the actual request.

We encountered this bug because we had the following setup:

  class MinimumReproducibleController < ActionController::Base
    before_filter { @param = 'param' }

    def index
      render text: url_for(params)
    end

    def default_url_options
      { custom_opt: @param }
    end
  end

  def test_index
    get :index # builds url, then fires actual request
  end

The first step in  `get :index` in the test suite would populate the
@_url_options cache. The subsequent call to `url_for` inside of the
controller action would then utilize the uncleared cache, thus never
calling the now-updated default_url_options.

This commit fixes this bug calling recycle! twice, and removes a call
to set response_body, which should no longer be needed since we're
recycling the request object explicitly.
2014-02-26 10:39:44 -08:00
Carlos Antonio da Silva
71b3910a7d Point master changelogs to 4-1-stable branch
Remove 4-1 related entries from master [ci skip]
2014-02-25 09:14:36 -03:00
Prem Sichanugrist
920f3ba266 Introduce render :html for render HTML string
This is an option for to HTML content with a content type of
`text/html`. This rendering option calls `ERB::Util.html_escape`
internally to escape unsafe HTML string, so you will have to mark your
string as html safe if you have any HTML tag in it.

Please see #12374 for more detail.
2014-02-18 12:08:36 -05:00
Prem Sichanugrist
8cd9f6d205 Introduce render :plain for render plain text
This is as an option to render content with a content type of
`text/plain`. This is the preferred option if you are planning to render
a plain text content.

Please see #12374 for more detail.
2014-02-18 12:08:36 -05:00
Prem Sichanugrist
103e18c87d Introduce render :body for render raw content
This is an option for sending a raw content back to browser. Note that
this rendering option will unset the default content type and does not
include "Content-Type" header back in the response.

You should only use this option if you are expecting the "Content-Type"
header to not be set. More information on "Content-Type" header can be
found on RFC 2616, section 7.2.1.

Please see #12374 for more detail.
2014-02-18 12:08:36 -05:00
Kevin Casey
8508346dd0 Correct prestreaming controller response status.
if the controller action has not yet streamed any data, actions should
process as normal, and errors should trigger the appropriate behavior
(500, or in the case of ActionController::BadRequest, a 400 Bad Request)
2014-02-15 13:05:00 -08:00
Godfrey Chan
0b86a6e950 Updated CHANGELOG, docs, guides and release notes.
Also added a `cookies_serializer.rb` initializer to the app template.
2014-02-11 02:52:07 -08:00
Godfrey Chan
ecf04f19b0 Added changelog entry for Flash changes [ci skip] 2014-02-11 01:54:58 -08:00
Andrew White
462d7cb314 Set the :shallow_path as each scope is generated
If we set :shallow_path when shallow is called it can result in incorrect
paths if the resource is inside a namespace because namespace itself sets
the :shallow_path option to the namespace path.

We fix this by removing the :shallow_path option from shallow as that should
only be turning shallow routes on and not otherwise affecting the scope.
To do this we need to treat the :shallow option to resources differently to
other scope options and move it to before the nested block is called.

This change also has the positive side effect of making the behavior of the
:shallow option consistent with the shallow method.

Fixes #12498.
2014-02-09 10:46:07 -08:00
Philipe Fatio
47860b62b3 Require action_view to fix missing constant
Previously, requiring action_view/view_paths did cause an uninitialized
constant error for ENCODING_FLAG, which is defined in action_view.
2014-02-07 17:48:18 +01:00
Yves Senn
580f0b61dc synchronize 4.1 release notes with CHANGELOGS. [ci skip]
/cc @chancancode
2014-02-06 11:43:16 +01:00
Rafael Mendonça França
e9be1c1e80 Merge pull request #13863 from joshjordan/jsj-dont-throw-out-get-params
Do not discard query parameters on requests that use wrap_parameters

Conflicts:
	actionpack/CHANGELOG.md
2014-02-01 15:53:27 -02:00
Josh Jordan
1f9586fd47 Do not discard query parameters on requests that use wrap_parameters 2014-01-30 18:20:55 -05:00
Yves Senn
02f9f33142 tidy CHANGELOGs [ci skip] 2014-01-30 11:12:46 +01:00
Guillermo Iguaran
fd487860db Modify the session serializer implementation
Rename allowed options to :marshal and :json, for custom serializers
only allow the use of custom classes.
2014-01-30 01:53:19 -05:00
Guillermo Iguaran
0f156100a2 Update CHANGELOG properly with GH #13692 [ci-skip] 2014-01-29 13:52:25 -05:00
Lukasz Sarnacki
b23ffd0dac Allow session serializer key in config.session_store
MessageEncryptor has :serializer option, where any serializer object can
be passed. This commit make it possible to set this serializer from configuration
level.

There are predefined serializers (:marshal_serializer, :json_serialzier)
and custom serializer can be passed as String, Symbol (camelized and
constantized in ActionDispatch::Session namepspace) or serializer object.

Default :json_serializer was also added to generators to provide secure
defalt.
2014-01-29 17:05:00 +01:00
Lukasz Sarnacki
69ab91ae93 Log which keys were set to nil in deep_munge
deep_munge solves CVE-2013-0155 security vulnerability, but its
behaviour is definately confuisng. This commit adds logging to deep_munge.
It logs keys for which values were set to nil.

Also mentions in guides were added.
2014-01-28 20:29:38 +01:00
Andrew White
3161606803 Clear filtered request attributes between requests in tests
The request attributes filtered_parameters, filtered_env and filtered_path
are memoized for performance reasons. However this can cause unusual
behavior in tests where there are multiple calls to get, post, etc.

Fixes #13803.
2014-01-27 13:30:28 +00:00
Maurizio De Santis
c1f8a0d614 Fix rake routes error when Rails::Engine with empty routes is mounted; fixes rails/rails#13810
Squash
2014-01-24 12:41:48 +01:00
Andrew White
bf191318af Tidy up tests and CHANGELOG for #12598 2014-01-20 16:34:22 +00:00
Amr Tamimi
746abbcc31 Automatically convert dashes to underscores for url helpers 2014-01-20 15:24:30 +00:00
Piotr Sarnacki
2e0f9ed76e Revert "Don't remove trailing slash from PATH_INFO for mounted apps"
The revert is needed because of a regression described in #13369, routes
with trailing slash are no longer recognized properly.

This reverts commit 50311f1391ddd8e0349d74eb57f04b7e0045a27d.
2014-01-16 10:13:51 +01:00
Aaron Patterson
caa981d881 Merge branch 'master' into laurocaetano-fix_send_file
* master: (536 commits)
  doc, API example on how to use `Model#exists?` with multiple IDs. [ci skip]
  Restore DATABASE_URL even if it's nil in connection_handler test
  [ci skip] - error_messages_for has been deprecated since 2.3.8 - lets reduce any confusion for users
  Ensure Active Record connection consistency
  Revert "ask the fixture set for the sql statements"
  Check `respond_to` before delegation due to: d781caaf31
  Adding Hash#compact and Hash#compact! methods
  MySQL version 4.1 was EOL on December 31, 2009 We should at least recommend modern versions of MySQL to users.
  clear cache on body close so that cache remains during rendering
  add a more restricted codepath for templates fixes #13390
  refactor generator tests to use block form of Tempfile
  Fix typo [ci skip]
  Move finish_template as the last public method in the generator
  Minor typos fix [ci skip]
  make `change_column_null` reversible. Closes #13576.
  create/drop test and development databases only if RAILS_ENV is nil
  Revert "Speedup String#to"
  typo fix in test name. [ci skip].
  `core_ext/string/access.rb` test what we are documenting.
  Fix typo in image_tag documentation
  ...

Conflicts:
	actionpack/CHANGELOG.md
2014-01-10 11:00:30 -08:00
Yves Senn
2d1d426c67 add example to the CHANGELOG entry from 3a48b83e5 [ci skip].
/cc @pixeltrix
2014-01-06 14:18:53 +01:00
Yves Senn
535bd55fcd quick formatting pass through CHANGELOGS. [ci skip]. 2014-01-06 10:57:00 +01:00
Andrew White
3a48b83e5e Allow an absolute controller path inside a module scope
Fixes #12777
2014-01-05 19:58:04 +00:00
Andrew White
6b54883082 Unique the segment keys array for non-optimized url helpers
In Rails 3.2 you only needed pass an argument for dynamic segment once so
unique the segment keys array to match the number of args. Since the number
of args is less than required parts the non-optimized code path is selected.
This means to benefit from optimized url generation the arg needs to be
specified as many times as it appears in the path.

Fixes #12808
2014-01-05 11:57:50 +00:00
Andrew White
892c539591 Show full route constraints in error message
When an optimized helper fails to generate, show the full route constraints
in the error message. Previously it would only show the contraints that were
required as part of the path.

Fixes #13592
2014-01-05 10:27:46 +00:00
Andrew White
d017e92e1d Use a custom route vistor for optimized route generation
Using a Regexp to replace dynamic segments in a path string is fraught
with difficulty and can lead to odd edge cases like #13349. Since we
already have a parsed representation of the path it makes sense to use
that to generate an array of segments that can be used to build an
optimized route's path quickly.

Tests on a simple route (e.g. /posts/:id) show a speedup of 35%:
https://gist.github.com/pixeltrix/8261932

Calculating -------------------------------------
    Current Helper:       5274 i/100ms
    New Helper:           8050 i/100ms
-------------------------------------------------
    Current Helper:     79263.6 (±3.7%) i/s -     395550 in   4.997252s
    New Helper:        153464.5 (±4.9%) i/s -     772800 in   5.047834s

Tests on a more complex route show even an greater performance boost:
https://gist.github.com/pixeltrix/8261957

Calculating -------------------------------------
    Current Helper:       2367 i/100ms
    New Helper:           5382 i/100ms
-------------------------------------------------
    Current Helper:     29506.0 (±3.2%) i/s -     149121 in   5.059294s
    New Helper:         78815.5 (±4.1%) i/s -     398268 in   5.062161s

It also has the added benefit of fixing the edge cases described above.

Fixes #13349
2014-01-05 00:36:25 +00:00
Andrew White
b64bac489c Allow engine root relative redirects using an empty string.
Example:

    # application routes.rb
    mount BlogEngine => '/blog'

    # engine routes.rb
    get '/welcome' => redirect('')

This now redirects to the path `/blog`, whereas before it would redirect
to the application root path. In the case of a path redirect or a custom
redirect if the path returned contains a host then the path is treated as
absolute. Similarly for option redirects, if the options hash returned
contains a `:host` or `:domain` key then the path is treated as absolute.

Fixes #7977
2014-01-01 11:19:14 +00:00
David Heinemeier Hansson
b5fdeaac55 Merge pull request #13470 from strzalek/variants-all-any
Add any/all support for variants
2013-12-31 09:57:09 -08:00
Andrew White
436ed51711 Fix Encoding::CompatibilityError when public path is UTF-8
In #5337 we forced the path encoding to ASCII-8BIT to prevent static
file handling from blowing up before an application has had chance to
deal with possibly invalid urls. However this has a negative side
effect of making it an incompatible encoding if the application's
public path has UTF-8 characters in it.

To work around the problem we check to see if the path has a valid
encoding once it has been unescaped. If it is not valid then we can
return early since it will not match any file anyway.

Fixes #13518
2013-12-29 18:38:53 +00:00
Łukasz Strzałkowski
a288cc1e01 Add any/all support for variants
Like `format.any`, you can do the same with variants.

It works for both inline:

    respond_to do |format|
      format.html.any   { render text: "any"   }
      format.html.phone { render text: "phone" }
    end

and block syntax:

    respond_to do |format|
      format.html do |variant|
        variant.any(:tablet, :phablet){ render text: "any" }
        variant.phone { render text: "phone" }
      end
    end
2013-12-26 20:36:17 +01:00
Xavier Noria
fa0380cb4a AC::Parameters#permit! permits hashes in array values 2013-12-23 22:55:03 +01:00
Carlos Antonio da Silva
618d5317d3 Move the null mime type to request.format
TLDR: always return an object that responds to the query methods from
request.format, and do not touch Mime::Type[] lookup to avoid bugs.

---

Long version:

The initial issue was about being able to do checks like
request.format.html? for request with an unknown format, where
request.format would be nil.

This is where the issue came from at first in #7837 and #8085
(merged in cba05887dc3b56a46a9fe2779b6b228880b49622), but the
implementation went down the path of adding this to the mime type
lookup logic.

This unfortunately introduced subtle bugs, for instance in the merged
commit a test related to send_file had to be changed to accomodate the
introduction of the NullType.

Later another bug was found in #13064, related to the content-type being
shown as #<Mime::NullType:...> for templates with localized extensions
but no format included. This one was fixed in #13133, merged in
43962d6ec50f918c9970bd3cd4b6ee5c7f7426ed.

Besides that, custom handlers were not receiving the proper template
formats anymore when passing through the rendering process, because of
the NullType addition. That was found while migrating an application
from 3.2 to 4.0 that uses the Markerb gem (a custom handler that
generates both text and html emails from a markdown template).

---

This changes the implementation moving away from returning this null
object from the mime lookup, and still fixes the initial issue where
request.format.zomg? would raise an exception for unknown formats due to
request.format being nil.
2013-12-23 16:16:49 -02:00
Xavier Noria
92f9ff8cc3 converts hashes in arrays of unfiltered params to unpermitted params [fixes #13382] 2013-12-21 01:16:38 +01:00
Jeremy Kemper
c437a98aca Merge pull request #13188 from imanel/skip_deep_munge
Add configuration option to optionally disable deep_munge

Conflicts:
	actionpack/CHANGELOG.md
2013-12-19 23:39:17 -07:00
Ryunosuke SATO
d54bc032c9 Show routes defined under assets prefix
Closes #9625
2013-12-19 09:51:17 -02:00
Jeremy Kemper
1650bb3d56 CSRF protection from cross-origin <script> tags
Thanks to @homakov for sounding the alarm about JSONP-style data leaking
2013-12-17 13:14:17 -07:00
Rafael Mendonça França
1454f2c20a Merge pull request #13290 from strzalek/inline-syntax-docs
Variants inline syntax documentation
2013-12-12 07:59:17 -08:00
Łukasz Strzałkowski
3ce9563d42 Variants inline syntax documentation [ci skip]
* Extend method documentation
  * Mention it in actionpack/CHANGELOG
  * Update release notes
2013-12-12 13:20:45 +01:00
Carlos Antonio da Silva
fe24f3560a Changelog improvements [ci skip] 2013-12-12 08:33:46 -02:00
Trent Ogren
96a6703ed9 Update CHANGELOG entry for Session#fetch
This reverts the changes to CHANGELOG.md in commit
38f8872aa5fd8f0a1d0895e9eb41f73261acd040.
2013-12-11 19:26:45 -06:00
Piotr Sarnacki
e6c602da90 Fix mounting engines inside a resources block
When a route is mounted inside a resources block, it's automatically
prefixed, so a following code:

    resources :users do
      mount Blog::Engine => '/blog'
    end

will generate a user_blog path helper.

In order to access engine helpers, we also use "mounted_helpers", a list
of helpers associated with each mounted engine, so a path to blog's post
can be generated using user_blog.post_path(user, post).

The problem I'm fixing here is that mount used a raw :as option, without
taking nestings into account. As a result, blog was added to a route set
as a `user_blog`, but helper was generated for just `blog`.

This commit applies the proper logic for defining a helper for a mounted
engine nested in resources or resource block.

(closes #8533)
2013-12-10 21:38:41 +01:00
David Heinemeier Hansson
13dd38cee7 Add Mime::Type.register "text/vcard", :vcf to the default list of mime types 2013-12-05 15:49:06 -08:00
Bernard Potocki
e8572cf2f9 Add configuration option to optionally disable deep_munge 2013-12-05 12:08:34 +01:00
Yves Senn
d71c1fc6a7 add missing CHANGELOG entry for d8c6f52. [ci skip]
Discoverd by #13175.
2013-12-05 11:41:12 +01:00
Shota Fukumori (sora_h)
c1d5477b63 Escalate missing error when :raise is true
Before ec16ba75a5493b9da972eea08bae630eba35b62f,
ActionView::Helpers::TranslationHelper#translate has raised errors with
specifying options[:raise] to true.

This should work by this fix:

     begin
       t(:"translations.missing", raise: true)
     rescue I18n::MissingTranslationData
       p :hello!
     end
2013-12-05 09:20:58 +09:00
Rafael Mendonça França
2d061c2c4f Update changelog [ci skip] 2013-12-04 17:48:32 -02:00
Łukasz Strzałkowski
2d3a6a0cb8 Action Pack Variants
By default, variants in the templates will be picked up if a variant is set
and there's a match. The format will be:

  app/views/projects/show.html.erb
  app/views/projects/show.html+tablet.erb
  app/views/projects/show.html+phone.erb

If request.variant = :tablet is set, we'll automatically be rendering the
html+tablet template.

In the controller, we can also tailer to the variants with this syntax:

  class ProjectsController < ActionController::Base
    def show
      respond_to do |format|
        format.html do |html|
          @stars = @project.stars

          html.tablet { @notifications = @project.notifications }
          html.phone  { @chat_heads    = @project.chat_heads }
        end

        format.js
        format.atom
      end
    end
  end

The variant itself is nil by default, but can be set in before filters, like
so:

  class ApplicationController < ActionController::Base
    before_action do
      if request.user_agent =~ /iPad/
        request.variant = :tablet
      end
    end
  end

This is modeled loosely on custom mime types, but it's specifically not
intended to be used together. If you're going to make a custom mime type,
you don't need a variant. Variants are for variations on a single mime
types.
2013-12-04 00:13:16 +01:00
Carlos Antonio da Silva
7c20a8b558 Changelog improvements [ci skip] 2013-12-03 14:38:12 -02:00