From 6df507e884baa8566b685bb1c555e42185570160 Mon Sep 17 00:00:00 2001 From: Pavel Pravosud Date: Mon, 31 Mar 2014 22:33:53 -0400 Subject: Make AS::SafeBuffer#prepend act like String#prepend Make `#prepend` method modify instance in-place and return self instead of just returning modified value. That is exactly what `#prepend!` method was doing previously, so it's deprecated from now on. --- .../active_support/core_ext/string/output_safety.rb | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/string/output_safety.rb b/activesupport/lib/active_support/core_ext/string/output_safety.rb index eb02b6a442..db80cfa737 100644 --- a/activesupport/lib/active_support/core_ext/string/output_safety.rb +++ b/activesupport/lib/active_support/core_ext/string/output_safety.rb @@ -124,7 +124,7 @@ module ActiveSupport #:nodoc: class SafeBuffer < String UNSAFE_STRING_METHODS = %w( capitalize chomp chop delete downcase gsub lstrip next reverse rstrip - slice squeeze strip sub succ swapcase tr tr_s upcase prepend + slice squeeze strip sub succ swapcase tr tr_s upcase ) alias_method :original_concat, :concat @@ -169,15 +169,22 @@ module ActiveSupport #:nodoc: self[0, 0] end - def concat(value) - if !html_safe? || value.html_safe? - super(value) - else - super(ERB::Util.h(value)) + %w[concat prepend].each do |method_name| + define_method method_name do |value| + if !html_safe? || value.html_safe? + super(value) + else + super(ERB::Util.h(value)) + end end end alias << concat + def prepend!(value) + ActiveSupport::Deprecation.deprecation_warning "ActiveSupport::SafeBuffer#prepend!", :prepend + prepend value + end + def +(other) dup.concat(other) end -- cgit v1.2.3 From 848289589edb74767cb97de9ed37a545a8d8b901 Mon Sep 17 00:00:00 2001 From: Pavel Pravosud Date: Wed, 2 Apr 2014 09:19:50 -0400 Subject: DRY AS::SafeBuffer a bit using existing helper --- activesupport/lib/active_support/core_ext/string/output_safety.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/string/output_safety.rb b/activesupport/lib/active_support/core_ext/string/output_safety.rb index db80cfa737..85cc75ff9a 100644 --- a/activesupport/lib/active_support/core_ext/string/output_safety.rb +++ b/activesupport/lib/active_support/core_ext/string/output_safety.rb @@ -171,11 +171,7 @@ module ActiveSupport #:nodoc: %w[concat prepend].each do |method_name| define_method method_name do |value| - if !html_safe? || value.html_safe? - super(value) - else - super(ERB::Util.h(value)) - end + super(html_escape_interpolated_argument(value)) end end alias << concat -- cgit v1.2.3