diff options
author | José Valim <jose.valim@gmail.com> | 2012-02-29 22:30:51 +0100 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2012-02-29 16:13:29 -0800 |
commit | 55ac1b9d889ddfdeaa3d6eb9389d3cc7695b8e07 (patch) | |
tree | 80634a436ea6fb4b4374982d447f2e54e94989d3 /activesupport/lib | |
parent | dfa33fa3da2e8495f5647c553704297cdc857917 (diff) | |
download | rails-55ac1b9d889ddfdeaa3d6eb9389d3cc7695b8e07.tar.gz rails-55ac1b9d889ddfdeaa3d6eb9389d3cc7695b8e07.tar.bz2 rails-55ac1b9d889ddfdeaa3d6eb9389d3cc7695b8e07.zip |
Ensure [] respects the status of the buffer.
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/core_ext/string/output_safety.rb | 30 |
1 files changed, 18 insertions, 12 deletions
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 e3fa528efb..4089b02d45 100644 --- a/activesupport/lib/active_support/core_ext/string/output_safety.rb +++ b/activesupport/lib/active_support/core_ext/string/output_safety.rb @@ -98,19 +98,31 @@ module ActiveSupport #:nodoc: end end + def [](*args) + return super if args.size < 2 + + if html_safe? + new_safe_buffer = super + new_safe_buffer.instance_eval { @html_safe = true } + new_safe_buffer + else + to_str[*args] + end + end + def safe_concat(value) - raise SafeConcatError if dirty? + raise SafeConcatError unless html_safe? original_concat(value) end def initialize(*) - @dirty = false + @html_safe = true super end def initialize_copy(other) super - @dirty = other.dirty? + @html_safe = other.html_safe? end def clone_empty @@ -120,7 +132,7 @@ module ActiveSupport #:nodoc: end def concat(value) - if dirty? || value.html_safe? + if !html_safe? || value.html_safe? super(value) else super(ERB::Util.h(value)) @@ -133,7 +145,7 @@ module ActiveSupport #:nodoc: end def html_safe? - !dirty? + defined?(@html_safe) && @html_safe end def to_s @@ -161,18 +173,12 @@ module ActiveSupport #:nodoc: end # end def #{unsafe_method}!(*args) # def capitalize!(*args) - @dirty = true # @dirty = true + @html_safe = false # @html_safe = false super # super end # end EOT end end - - protected - - def dirty? - @dirty - end end end |