diff options
Diffstat (limited to 'activesupport/lib/active_support/core_ext/string')
3 files changed, 29 insertions, 25 deletions
diff --git a/activesupport/lib/active_support/core_ext/string/exclude.rb b/activesupport/lib/active_support/core_ext/string/exclude.rb new file mode 100644 index 0000000000..5ca268b953 --- /dev/null +++ b/activesupport/lib/active_support/core_ext/string/exclude.rb @@ -0,0 +1,6 @@ +class String + # The inverse of String#include?. Returns true if the string does not include the other string. + def exclude?(string) + !include?(string) + end +end diff --git a/activesupport/lib/active_support/core_ext/string/interpolation.rb b/activesupport/lib/active_support/core_ext/string/interpolation.rb index 41a061c1a4..2048d35091 100644 --- a/activesupport/lib/active_support/core_ext/string/interpolation.rb +++ b/activesupport/lib/active_support/core_ext/string/interpolation.rb @@ -5,7 +5,7 @@ You may redistribute it and/or modify it under the same license terms as Ruby. =end -if RUBY_VERSION < '1.9' +if RUBY_VERSION < '1.9' && !"".respond_to?(:interpolate_without_ruby_19_syntax) # KeyError is raised by String#% when the string contains a named placeholder # that is not contained in the given arguments hash. Ruby 1.9 includes and 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 2cca4763f4..ceed90ce79 100644 --- a/activesupport/lib/active_support/core_ext/string/output_safety.rb +++ b/activesupport/lib/active_support/core_ext/string/output_safety.rb @@ -1,43 +1,41 @@ -class String +class Object + def html_safe? + false + end +end + +class Fixnum def html_safe? - defined?(@_rails_html_safe) && @_rails_html_safe + true end +end + +class String + attr_accessor :_rails_html_safe + alias html_safe? _rails_html_safe def html_safe! @_rails_html_safe = true self end - + def html_safe dup.html_safe! end - + alias original_plus + def +(other) result = original_plus(other) - if html_safe? && also_html_safe?(other) - result.html_safe! - else - result - end + result._rails_html_safe = html_safe? && other.html_safe? + result end - + alias original_concat << + alias safe_concat << def <<(other) + @_rails_html_safe = false unless other.html_safe? result = original_concat(other) - unless html_safe? && also_html_safe?(other) - @_rails_html_safe = false - end - result - end - - def concat(other) - self << other end - - private - def also_html_safe?(other) - other.respond_to?(:html_safe?) && other.html_safe? - end - + + alias concat << end
\ No newline at end of file |