aboutsummaryrefslogtreecommitdiffstats
path: root/actionview
diff options
context:
space:
mode:
Diffstat (limited to 'actionview')
-rw-r--r--actionview/CHANGELOG.md7
-rw-r--r--actionview/Rakefile2
-rw-r--r--actionview/lib/action_view/helpers/capture_helper.rb4
-rw-r--r--actionview/lib/action_view/helpers/debug_helper.rb2
-rw-r--r--actionview/lib/action_view/helpers/number_helper.rb16
-rw-r--r--actionview/lib/action_view/helpers/text_helper.rb7
-rw-r--r--actionview/lib/action_view/layouts.rb2
-rw-r--r--actionview/test/abstract_unit.rb5
-rw-r--r--actionview/test/activerecord/debug_helper_test.rb6
-rw-r--r--actionview/test/fixtures/layouts/streaming_with_capture.erb6
-rw-r--r--actionview/test/template/number_helper_test.rb4
-rw-r--r--actionview/test/template/streaming_render_test.rb4
12 files changed, 47 insertions, 18 deletions
diff --git a/actionview/CHANGELOG.md b/actionview/CHANGELOG.md
index 101f1263d9..82a636315a 100644
--- a/actionview/CHANGELOG.md
+++ b/actionview/CHANGELOG.md
@@ -1,3 +1,10 @@
+* `number_to_percentage` does not crash with `Float::NAN` or `Float::INFINITY`
+ as input when `precision: 0` is used.
+
+ Fixes #19227.
+
+ *Yves Senn*
+
* Fixed the translation helper method to accept different default values types
besides String.
diff --git a/actionview/Rakefile b/actionview/Rakefile
index 1b71435948..2b752b83df 100644
--- a/actionview/Rakefile
+++ b/actionview/Rakefile
@@ -18,7 +18,7 @@ namespace :test do
Rake::TestTask.new(:template) do |t|
t.libs << 'test'
- t.test_files = Dir.glob('test/template/**/*_test.rb').sort
+ t.test_files = Dir.glob('test/template/**/*_test.rb')
t.warning = true
t.verbose = true
t.ruby_opts = ["--dev"] if defined?(JRUBY_VERSION)
diff --git a/actionview/lib/action_view/helpers/capture_helper.rb b/actionview/lib/action_view/helpers/capture_helper.rb
index 5a3223968f..a67ba580f1 100644
--- a/actionview/lib/action_view/helpers/capture_helper.rb
+++ b/actionview/lib/action_view/helpers/capture_helper.rb
@@ -195,7 +195,9 @@ module ActionView
def with_output_buffer(buf = nil) #:nodoc:
unless buf
buf = ActionView::OutputBuffer.new
- buf.force_encoding(output_buffer.encoding) if output_buffer
+ if output_buffer && output_buffer.respond_to?(:encoding)
+ buf.force_encoding(output_buffer.encoding)
+ end
end
self.output_buffer, old_buffer = buf, output_buffer
yield
diff --git a/actionview/lib/action_view/helpers/debug_helper.rb b/actionview/lib/action_view/helpers/debug_helper.rb
index ba47eee9ba..e9dccbad1c 100644
--- a/actionview/lib/action_view/helpers/debug_helper.rb
+++ b/actionview/lib/action_view/helpers/debug_helper.rb
@@ -26,7 +26,7 @@ module ActionView
Marshal::dump(object)
object = ERB::Util.html_escape(object.to_yaml)
content_tag(:pre, object, :class => "debug_dump")
- rescue Exception # errors from Marshal or YAML
+ rescue # errors from Marshal or YAML
# Object couldn't be dumped, perhaps because of singleton methods -- this is the fallback
content_tag(:code, object.inspect, :class => "debug_dump")
end
diff --git a/actionview/lib/action_view/helpers/number_helper.rb b/actionview/lib/action_view/helpers/number_helper.rb
index cfd617cedc..ca8d30e4ef 100644
--- a/actionview/lib/action_view/helpers/number_helper.rb
+++ b/actionview/lib/action_view/helpers/number_helper.rb
@@ -116,8 +116,8 @@ module ActionView
# (defaults to current locale).
# * <tt>:precision</tt> - Sets the precision of the number
# (defaults to 3).
- # * <tt>:significant</tt> - If +true+, precision will be the #
- # of significant_digits. If +false+, the # of fractional
+ # * <tt>:significant</tt> - If +true+, precision will be the number
+ # of significant_digits. If +false+, the number of fractional
# digits (defaults to +false+).
# * <tt>:separator</tt> - Sets the separator between the
# fractional and integer digits (defaults to ".").
@@ -191,8 +191,8 @@ module ActionView
# (defaults to current locale).
# * <tt>:precision</tt> - Sets the precision of the number
# (defaults to 3).
- # * <tt>:significant</tt> - If +true+, precision will be the #
- # of significant_digits. If +false+, the # of fractional
+ # * <tt>:significant</tt> - If +true+, precision will be the number
+ # of significant_digits. If +false+, the number of fractional
# digits (defaults to +false+).
# * <tt>:separator</tt> - Sets the separator between the
# fractional and integer digits (defaults to ".").
@@ -239,8 +239,8 @@ module ActionView
# (defaults to current locale).
# * <tt>:precision</tt> - Sets the precision of the number
# (defaults to 3).
- # * <tt>:significant</tt> - If +true+, precision will be the #
- # of significant_digits. If +false+, the # of fractional
+ # * <tt>:significant</tt> - If +true+, precision will be the number
+ # of significant_digits. If +false+, the number of fractional
# digits (defaults to +true+)
# * <tt>:separator</tt> - Sets the separator between the
# fractional and integer digits (defaults to ".").
@@ -291,8 +291,8 @@ module ActionView
# (defaults to current locale).
# * <tt>:precision</tt> - Sets the precision of the number
# (defaults to 3).
- # * <tt>:significant</tt> - If +true+, precision will be the #
- # of significant_digits. If +false+, the # of fractional
+ # * <tt>:significant</tt> - If +true+, precision will be the number
+ # of significant_digits. If +false+, the number of fractional
# digits (defaults to +true+)
# * <tt>:separator</tt> - Sets the separator between the
# fractional and integer digits (defaults to ".").
diff --git a/actionview/lib/action_view/helpers/text_helper.rb b/actionview/lib/action_view/helpers/text_helper.rb
index 2c40ed1832..c216d4401f 100644
--- a/actionview/lib/action_view/helpers/text_helper.rb
+++ b/actionview/lib/action_view/helpers/text_helper.rb
@@ -103,7 +103,9 @@ module ActionView
# Highlights one or more +phrases+ everywhere in +text+ by inserting it into
# a <tt>:highlighter</tt> string. The highlighter can be specialized by passing <tt>:highlighter</tt>
# as a single-quoted string with <tt>\1</tt> where the phrase is to be inserted (defaults to
- # '<mark>\1</mark>') or passing a block that receives each matched term.
+ # '<mark>\1</mark>') or passing a block that receives each matched term. By default +text+
+ # is sanitized to prevent possible XSS attacks. If the input is trustworthy, passing false
+ # for <tt>:sanitize</tt> will turn sanitizing off.
#
# highlight('You searched for: rails', 'rails')
# # => You searched for: <mark>rails</mark>
@@ -122,6 +124,9 @@ module ActionView
#
# highlight('You searched for: rails', 'rails') { |match| link_to(search_path(q: match, match)) }
# # => You searched for: <a href="search?q=rails">rails</a>
+ #
+ # highlight('<a href="javascript:alert(\'no!\')">ruby</a> on rails', 'rails', sanitize: false)
+ # # => "<a>ruby</a> on <mark>rails</mark>"
def highlight(text, phrases, options = {})
text = sanitize(text) if options.fetch(:sanitize, true)
diff --git a/actionview/lib/action_view/layouts.rb b/actionview/lib/action_view/layouts.rb
index 0b5c0b9991..9d636c8c9e 100644
--- a/actionview/lib/action_view/layouts.rb
+++ b/actionview/lib/action_view/layouts.rb
@@ -228,7 +228,7 @@ module ActionView
# set by the <tt>layout</tt> method.
#
# ==== Returns
- # * <tt> Boolean</tt> - True if the action has a layout definition, false otherwise.
+ # * <tt>Boolean</tt> - True if the action has a layout definition, false otherwise.
def _conditional_layout?
return unless super
diff --git a/actionview/test/abstract_unit.rb b/actionview/test/abstract_unit.rb
index fc1ca9efdf..3eded74f1b 100644
--- a/actionview/test/abstract_unit.rb
+++ b/actionview/test/abstract_unit.rb
@@ -338,8 +338,3 @@ def jruby_skip(message = '')
end
require 'mocha/setup' # FIXME: stop using mocha
-
-# FIXME: we have tests that depend on run order, we should fix that and
-# remove this method call.
-require 'active_support/test_case'
-ActiveSupport::TestCase.test_order = :sorted
diff --git a/actionview/test/activerecord/debug_helper_test.rb b/actionview/test/activerecord/debug_helper_test.rb
index 5609694cd5..03cb1d5a91 100644
--- a/actionview/test/activerecord/debug_helper_test.rb
+++ b/actionview/test/activerecord/debug_helper_test.rb
@@ -1,8 +1,14 @@
require 'active_record_unit'
+require 'nokogiri'
class DebugHelperTest < ActionView::TestCase
def test_debug
company = Company.new(name: "firebase")
assert_match "name: firebase", debug(company)
end
+
+ def test_debug_with_marshal_error
+ obj = -> { }
+ assert_match obj.inspect, Nokogiri.XML(debug(obj)).content
+ end
end
diff --git a/actionview/test/fixtures/layouts/streaming_with_capture.erb b/actionview/test/fixtures/layouts/streaming_with_capture.erb
new file mode 100644
index 0000000000..538c19ce3a
--- /dev/null
+++ b/actionview/test/fixtures/layouts/streaming_with_capture.erb
@@ -0,0 +1,6 @@
+<%= yield :header -%>
+<%= capture do %>
+ this works
+<% end %>
+<%= yield :footer -%>
+<%= yield(:unknown).presence || "." -%>
diff --git a/actionview/test/template/number_helper_test.rb b/actionview/test/template/number_helper_test.rb
index b59883b760..b70b750869 100644
--- a/actionview/test/template/number_helper_test.rb
+++ b/actionview/test/template/number_helper_test.rb
@@ -35,6 +35,10 @@ class NumberHelperTest < ActionView::TestCase
assert_equal "98a%", number_to_percentage("98a")
assert_equal "NaN%", number_to_percentage(Float::NAN)
assert_equal "Inf%", number_to_percentage(Float::INFINITY)
+ assert_equal "NaN%", number_to_percentage(Float::NAN, precision: 0)
+ assert_equal "Inf%", number_to_percentage(Float::INFINITY, precision: 0)
+ assert_equal "NaN%", number_to_percentage(Float::NAN, precision: 1)
+ assert_equal "Inf%", number_to_percentage(Float::INFINITY, precision: 1)
end
def test_number_with_delimiter
diff --git a/actionview/test/template/streaming_render_test.rb b/actionview/test/template/streaming_render_test.rb
index ec537775be..d06ba4ceb0 100644
--- a/actionview/test/template/streaming_render_test.rb
+++ b/actionview/test/template/streaming_render_test.rb
@@ -104,4 +104,8 @@ class FiberedTest < ActiveSupport::TestCase
buffered_render(:template => "test/nested_streaming", :layout => "layouts/streaming")
end
+ def test_render_with_streaming_and_capture
+ assert_equal "Yes, \n this works\n like a charm.",
+ buffered_render(template: "test/streaming", layout: "layouts/streaming_with_capture")
+ end
end