Commit Graph

8893 Commits

Author SHA1 Message Date
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
Andrew White
54ccc58c62 Fix method redefined warning message in mapper.rb 2013-12-29 17:55:54 +00:00
Chun-wei Kuo
fbbd4e1899 Improve font of some code in API documentation [ci skip]
* Add "<tt>" or "+" to improve font of some code and filenames in API documentation
* Does not contain wording changes
2013-12-26 18:54:46 +08: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
Łukasz Strzałkowski
2e033e2799 Add missing av/railtie require 2013-12-22 22:54:51 +01:00
Xavier Noria
273045d6d5 optimizes array conversion in AC::Parameters 2013-12-21 14:22:08 +01:00
Xavier Noria
269424b0bb refactors AC::Parameters#fetch
AC::Parameters#fetch was refactored in 7171111 to prevent self mutation, but
in doing so it hardcodes logic #convert_hashes_to_parameters is supposed to
encapsulate.

Better leave the delegation, and add a way to avoid mutating self in there.
2013-12-21 13:47:26 +01: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
Vijay Dev
a3b1105ada Merge branch 'master' of github.com:lifo/docrails 2013-12-20 00:10:30 +05:30
Ryunosuke SATO
d54bc032c9 Show routes defined under assets prefix
Closes #9625
2013-12-19 09:51:17 -02:00
Vipul A M
7bae2921ec Change all MiniTest to Minitest since, MiniTest namespace has been renamed to Minitest
Ref: https://github.com/seattlerb/minitest/blob/master/History.txt
2013-12-18 14:39:50 +05:30
David Heinemeier Hansson
c0a2d474c5 Get ready to release 4.1.0.beta1 2013-12-17 16:05:28 -08:00
Jeremy Kemper
4f4fdd643f Clearly limit new CSRF protection to GET requests 2013-12-17 16:02:04 -07:00
Jeremy Kemper
39ca25f5c4 Merge pull request #13345 from jeremy/get-csrf
CSRF protection from cross-origin <script> tags
2013-12-17 12:29:57 -08: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
Godfrey Chan
2003d0409e Some assorted fixes for the 4.1 release notes:
* Added release notes for secrets.yml and mentioned it in the highlights
* Added release notes for Mailer previews and mentioned it in the highlights
* Added release notes for Module#concerning
* Removed mention for AV extraction from the highlights
* Rearranged the major features to put highlighted features first
* Various improvements and typo fixes

[ci skip]
2013-12-17 08:39:07 -08:00
Andrew White
d6dec7fcb6 Add mailer previews feature based on mail_view gem 2013-12-17 03:58:35 +00:00
robertomiranda
35d0d6fec5 Update secret_key_base Docs 2013-12-15 10:32:41 -05:00
Philipe Fatio
fd76b9d546 Fix syntax error in redirect_to example
Without parenthesis, ruby assumes that curly braces denote the beginning
of a block.
2013-12-14 15:35:50 +01:00
Carlos Antonio da Silva
07fd25c759 Merge pull request #13293 from akshay-vishnoi/typo
Spelling and Grammar checks [ci skip]
2013-12-12 08:12:13 -08:00
Akshay Vishnoi
5fccd77b6c Spelling and Grammar checks 2013-12-12 18:28:34 +05:30
Ł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
Damien Mathieu
6645a2099a Merge pull request #13288 from dvsuresh/fix_typo
Fix typo in action_controller responder.rb [ci skip]
2013-12-12 00:13:52 -08:00
dvsuresh
25a5c5f236 Fix typo in action_controller responder.rb 2013-12-12 02:03:58 -06:00
Godfrey Chan
ebfd97124d Merge pull request #13284 from aayushkhandelwal11/typos_corrected
s/everytime/every time/
2013-12-11 22:13:04 -08:00
Aayush khandelwal
4a9e54ef35 typos rectified [ci skip] 2013-12-12 11:29:23 +05:30
Trent Ogren
d0fc760d09 Make ActionDispatch::Request::Session#fetch behave like Hash#fetch
Session#fetch was mutating the session when given a default argument
and/or a block. Since Session duck-types as a Hash, it should behave
like one in these cases.
2013-12-11 15:29:33 -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
Łukasz Strzałkowski
edacdbfaf9 Inline variants syntax
In most cases, when setting variant specific code, you're not sharing any code
within format.

Inline syntax can vastly simplify defining variants in those situations:

  respond_to do |format|
    format.js { render "trash" }
    format.html do |variant|
      variant.phone { redirect_to progress_path }
      variant.none  { render "trash" }
    end
  end

Becomes:

  respond_to do |format|
    format.js         { render "trash" }
    format.html.phone { redirect_to progress_path }
    format.html.none  { render "trash" }
  end
2013-12-10 11:55:43 +01:00
Łukasz Strzałkowski
fbb6be50a5 Simplify @responses hash initialization
@responses hash needs to be initialized with mime types that we get from
Collector#collect_mimes_from_class_level. Mime::Type class as key and nil as
value. This need to happen before content negotiation. Before that, it was
looping though mime types and executing mime-type-generated method inside
collector (see
AbstractController::Collector#generate_method_for_mime). That approach resulted
in 2 unnecessary method calls for each mime type
collected by Collector#collect_mimes_from_class_level.

Now hash is initialized in place, without usage of Collector#custom method.
2013-12-10 11:47:50 +01:00
David Heinemeier Hansson
4aae538d9f Revert "Merge pull request #13235 from strzalek/variants-inline" -- needs a little more work!
This reverts commit 186161148a189839a1e0924043f068a8d155ce69, reversing
changes made to cad9eb178ea5eec0e27d74e93518f4ed34e2f997.
2013-12-08 14:04:04 -08:00
David Heinemeier Hansson
186161148a Merge pull request #13235 from strzalek/variants-inline
Inline syntax for variants
2013-12-08 13:38:01 -08:00
Łukasz Strzałkowski
2647d2f656 Inline variants syntax
In most cases, when setting variant specific code, you're not sharing any code
within format.

Inline syntax can vastly simplify defining variants in those sitiations:

  respond_to do |format|
    format.js { render "trash" }
    format.html do |variant|
      variant.phone { redirect_to progress_path }
      variant.none  { render "trash" }
    end
  end
`
Becomes:

  respond_to do |format|
    format.js         { render "trash" }
    format.html.phone { redirect_to progress_path }
    format.html.none  { render "trash" }
  end
2013-12-08 22:29:07 +01:00
Łukasz Strzałkowski
9b8c0ff391 Simplify @responses hash initialization
@responses hash needs to be initialized with mime types that we get from
Collector#collect_mimes_from_class_level. Mime::Type class as key and nil as
value. This need to happen before content negotiation. Before that, it was
looping though mime types and executing mime-type-generated method inside
collector (see
AbstractController::Collector#generate_method_for_mime). That approach resulted
in 2 unnecessary method calls for each mime type
collected by Collector#collect_mimes_from_class_level.

Now hash is initialized in place, without usage of Collector#custom method.
2013-12-08 22:11:46 +01:00
Łukasz Strzałkowski
d99dd0af03 Require action_view explicitly in AC::Base 2013-12-08 13:03:41 +01:00
David Heinemeier Hansson
99975e742e Variants can be declared without a block to signify their presence in the controller 2013-12-07 16:32:38 -08:00
David Heinemeier Hansson
a16fa9abfd Allow code execution in case no variant has been set with variant.none 2013-12-07 15:00:35 -08: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
Jeremy Kemper
5086c8c211 Merge pull request #13189 from strzalek/retain-ap-av-dep
Retain ActionPack dependency on ActionView. Fixes #12979.
2013-12-05 07:25:17 -08:00
Bernard Potocki
e8572cf2f9 Add configuration option to optionally disable deep_munge 2013-12-05 12:08:34 +01:00
Łukasz Strzałkowski
d8888b94b3 Retain ActionPack dependency on ActionView 2013-12-05 01:02:46 +01:00
Angelo capilleri
2f3fe92f1b remove nil in NullType#ref.
Return Nil is implicit in a method and this syntax is used in the others
classes
2013-12-04 17:55:05 +01:00
Carlos Antonio da Silva
3b40a5d83d Improve a couple exception messages related to variants and mime types
Avoid one-liner conditionals when they are too big. Avoid concatenating
strings to build error messages. Improve messages a bit.
2013-12-03 22:23:12 -02:00
Carlos Antonio da Silva
bc26f442d2 Add nodoc to added VariantFilter class 2013-12-03 22:08:18 -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
ce148025f2 Change deep_munge call to avoid deprecation warning 2013-12-03 20:25:03 -02:00
Aaron Patterson
dba82120fe Merge branch 'master-sec'
* master-sec:
  Deep Munge the parameters for GET and POST
  Stop using i18n's built in HTML error handling.
  Ensure simple_format escapes its html attributes
  Escape the unit value provided to number_to_currency
  Only use valid mime type symbols as cache keys
2013-12-03 11:01:56 -08:00
Lauro Caetano
b1b9a0aeca Typos. return -> returns. [ci skip] 2013-12-03 13:31:36 -02:00