aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/CHANGELOG.md9
-rw-r--r--actionpack/lib/action_controller/caching.rb4
-rw-r--r--actionpack/lib/action_view/helpers/url_helper.rb2
-rw-r--r--actionpack/test/template/url_helper_test.rb6
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb6
-rw-r--r--activesupport/CHANGELOG.md2
-rw-r--r--activesupport/lib/active_support/core_ext/object/try.rb52
-rw-r--r--activesupport/lib/active_support/core_ext/string/filters.rb7
-rw-r--r--activesupport/test/core_ext/string_ext_test.rb7
-rw-r--r--guides/source/active_support_core_extensions.md2
10 files changed, 61 insertions, 36 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md
index a35caf6a94..a953a78417 100644
--- a/actionpack/CHANGELOG.md
+++ b/actionpack/CHANGELOG.md
@@ -1,7 +1,12 @@
## Rails 4.0.0 (unreleased) ##
-* Change asset_path to not include `SCRIPT_NAME` when it's used
- from a mounted engine (fixes #8119).
+* Fix CSRF protection and `current_url?` helper to work with HEAD requests
+ now that `ActionDispatch::Head` has been removed in favor of `Rack::Head`.
+
+ *Michiel Sikkes*
+
+* Change `asset_path` to not include `SCRIPT_NAME` when it's used
+ from a mounted engine. Fixes #8119.
*Piotr Sarnacki*
diff --git a/actionpack/lib/action_controller/caching.rb b/actionpack/lib/action_controller/caching.rb
index cf2cda039d..ea33d975ef 100644
--- a/actionpack/lib/action_controller/caching.rb
+++ b/actionpack/lib/action_controller/caching.rb
@@ -82,10 +82,6 @@ module ActionController
end
end
- def caching_allowed?
- request.get? && response.status == 200
- end
-
def view_cache_dependencies
self.class._view_cache_dependencies.map { |dep| instance_exec(&dep) }.compact
end
diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb
index bade121d44..5e20b557d8 100644
--- a/actionpack/lib/action_view/helpers/url_helper.rb
+++ b/actionpack/lib/action_view/helpers/url_helper.rb
@@ -514,7 +514,7 @@ module ActionView
"in a #request method"
end
- return false unless request.get?
+ return false unless request.get? || request.head?
url_string = url_for(options)
diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb
index ba65349b6a..5d87c96605 100644
--- a/actionpack/test/template/url_helper_test.rb
+++ b/actionpack/test/template/url_helper_test.rb
@@ -437,6 +437,12 @@ class UrlHelperTest < ActiveSupport::TestCase
ActionDispatch::Request.new(env)
end
+ def test_current_page_with_http_head_method
+ @request = request_for_url("/", :method => :head)
+ assert current_page?(url_hash)
+ assert current_page?("http://www.example.com/")
+ end
+
def test_current_page_with_simple_url
@request = request_for_url("/")
assert current_page?(url_hash)
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb b/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb
index be6fda95b4..41e07fbda9 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb
@@ -9,9 +9,9 @@ module ActiveRecord
def dirties_query_cache(base, *method_names)
method_names.each do |method_name|
base.class_eval <<-end_code, __FILE__, __LINE__ + 1
- def #{method_name}(*) # def update_with_query_dirty(*args)
+ def #{method_name}(*) # def update_with_query_dirty(*)
clear_query_cache if @query_cache_enabled # clear_query_cache if @query_cache_enabled
- super # update_without_query_dirty(*args)
+ super # super
end # end
end_code
end
@@ -85,6 +85,8 @@ module ActiveRecord
end
end
+ # If arel is locked this is a SELECT ... FOR UPDATE or somesuch. Such
+ # queries should not be cached.
def locked?(arel)
arel.respond_to?(:locked) && arel.locked
end
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md
index 72f28aefc7..a2e6c62c3e 100644
--- a/activesupport/CHANGELOG.md
+++ b/activesupport/CHANGELOG.md
@@ -1,5 +1,7 @@
## Rails 4.0.0 (unreleased) ##
+* Improve `String#squish` to handle Unicode whitespace. *Antoine Lyset*
+
* Standardise on `to_time` returning an instance of `Time` in the local system timezone
across `String`, `Time`, `Date`, `DateTime` and `ActiveSupport::TimeWithZone`.
diff --git a/activesupport/lib/active_support/core_ext/object/try.rb b/activesupport/lib/active_support/core_ext/object/try.rb
index 1079ddde98..534bbe3c42 100644
--- a/activesupport/lib/active_support/core_ext/object/try.rb
+++ b/activesupport/lib/active_support/core_ext/object/try.rb
@@ -1,35 +1,43 @@
class Object
- # Invokes the public method identified by the symbol +method+, passing it any arguments
- # and/or the block specified, just like the regular Ruby <tt>Object#public_send</tt> does.
+ # Invokes the public method whose name goes as first argument just like
+ # +public_send+ does, except that if the receiver does not respond to it the
+ # call returns +nil+ rather than raising an exception.
#
- # *Unlike* that method however, a +NoMethodError+ exception will *not* be raised
- # and +nil+ will be returned instead, if the receiving object is a +nil+ object or NilClass.
+ # This method is defined to be able to write
#
- # This is also true if the receiving object does not implemented the tried method. It will
- # return +nil+ in that case as well.
- #
- # If try is called without a method to call, it will yield any given block with the object.
+ # @person.try(:name)
#
- # Please also note that +try+ is defined on +Object+, therefore it won't work with
- # subclasses of +BasicObject+. For example, using try with +SimpleDelegator+ will
- # delegate +try+ to target instead of calling it on delegator itself.
+ # instead of
#
- # Without +try+
- # @person && @person.name
- # or
# @person ? @person.name : nil
#
- # With +try+
- # @person.try(:name)
+ # +try+ returns +nil+ when called on +nil+ regardless of whether it responds
+ # to the method:
+ #
+ # nil.try(:to_i) # => nil, rather than 0
+ #
+ # Arguments and blocks are forwarded to the method if invoked:
+ #
+ # @posts.try(:each_slice, 2) do |a, b|
+ # ...
+ # end
+ #
+ # The number of arguments in the signature must match. If the object responds
+ # to the method the call is attempted and +ArgumentError+ is still raised
+ # otherwise.
#
- # +try+ also accepts arguments and/or a block, for the method it is trying
- # Person.try(:find, 1)
- # @people.try(:collect) {|p| p.name}
+ # If +try+ is called without arguments it yields the receiver to a given
+ # block unless it is +nil+:
#
- # Without a method argument try will yield to the block unless the receiver is nil.
- # @person.try { |p| "#{p.first_name} #{p.last_name}" }
+ # @person.try do |p|
+ # ...
+ # end
#
- # +try+ behaves like +Object#public_send+, unless called on +NilClass+.
+ # Please also note that +try+ is defined on +Object+, therefore it won't work
+ # with instances of classes that do not have +Object+ among their ancestors,
+ # like direct subclasses of +BasicObject+. For example, using +try+ with
+ # +SimpleDelegator+ will delegate +try+ to the target instead of calling it on
+ # delegator itself.
def try(*a, &b)
if a.empty? && block_given?
yield self
diff --git a/activesupport/lib/active_support/core_ext/string/filters.rb b/activesupport/lib/active_support/core_ext/string/filters.rb
index e05447439a..a1b3f79748 100644
--- a/activesupport/lib/active_support/core_ext/string/filters.rb
+++ b/activesupport/lib/active_support/core_ext/string/filters.rb
@@ -3,6 +3,8 @@ class String
# the string, and then changing remaining consecutive whitespace
# groups into one space each.
#
+ # Note that it handles both ASCII and Unicode whitespace like mongolian vowel separator (U+180E).
+ #
# %{ Multi-line
# string }.squish # => "Multi-line string"
# " foo bar \n \t boo".squish # => "foo bar boo"
@@ -12,8 +14,9 @@ class String
# Performs a destructive squish. See String#squish.
def squish!
- strip!
- gsub!(/\s+/, ' ')
+ gsub!(/\A[[:space:]]+/, '')
+ gsub!(/[[:space:]]+\z/, '')
+ gsub!(/[[:space:]]+/, ' ')
self
end
diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb
index 68918b040f..bff155f045 100644
--- a/activesupport/test/core_ext/string_ext_test.rb
+++ b/activesupport/test/core_ext/string_ext_test.rb
@@ -229,10 +229,11 @@ class StringInflectionsTest < ActiveSupport::TestCase
end
def test_string_squish
- original = %{ A string with tabs(\t\t), newlines(\n\n), and
- many spaces( ). }
+ original = %{\u180E\u180E A string surrounded by unicode mongolian vowel separators,
+ with tabs(\t\t), newlines(\n\n), unicode nextlines(\u0085\u0085) and many spaces( ). \u180E\u180E}
- expected = "A string with tabs( ), newlines( ), and many spaces( )."
+ expected = "A string surrounded by unicode mongolian vowel separators, " +
+ "with tabs( ), newlines( ), unicode nextlines( ) and many spaces( )."
# Make sure squish returns what we expect:
assert_equal original.squish, expected
diff --git a/guides/source/active_support_core_extensions.md b/guides/source/active_support_core_extensions.md
index 3c1bb0f132..f02b377832 100644
--- a/guides/source/active_support_core_extensions.md
+++ b/guides/source/active_support_core_extensions.md
@@ -1233,6 +1233,8 @@ The method `squish` strips leading and trailing whitespace, and substitutes runs
There's also the destructive version `String#squish!`.
+Note that it handles both ASCII and Unicode whitespace like mongolian vowel separator (U+180E).
+
NOTE: Defined in `active_support/core_ext/string/filters.rb`.
### `truncate`