diff options
author | wycats <wycats@gmail.com> | 2010-05-15 03:47:24 -0700 |
---|---|---|
committer | wycats <wycats@gmail.com> | 2010-05-16 22:43:35 +0400 |
commit | af0d1a88157942c6e6398dbf73891cff1e152405 (patch) | |
tree | 75053e7b5f3323c986e6a1e2d4a859e8010d284c /activesupport | |
parent | f8432108e85c06ab8939869ece0297e72c21e7fe (diff) | |
download | rails-af0d1a88157942c6e6398dbf73891cff1e152405.tar.gz rails-af0d1a88157942c6e6398dbf73891cff1e152405.tar.bz2 rails-af0d1a88157942c6e6398dbf73891cff1e152405.zip |
Initial work to improve the state of encodings for templates
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/core_ext/string/encoding.rb | 11 | ||||
-rw-r--r-- | activesupport/lib/active_support/ruby/shim.rb | 1 | ||||
-rw-r--r-- | activesupport/test/core_ext/string_ext_test.rb | 8 |
3 files changed, 20 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/string/encoding.rb b/activesupport/lib/active_support/core_ext/string/encoding.rb new file mode 100644 index 0000000000..d4781bfe0c --- /dev/null +++ b/activesupport/lib/active_support/core_ext/string/encoding.rb @@ -0,0 +1,11 @@ +class String + if defined?(Encoding) && "".respond_to?(:encode) + def encoding_aware? + true + end + else + def encoding_aware? + false + end + end +end
\ No newline at end of file diff --git a/activesupport/lib/active_support/ruby/shim.rb b/activesupport/lib/active_support/ruby/shim.rb index 4a9ac920e8..608b3fe4b9 100644 --- a/activesupport/lib/active_support/ruby/shim.rb +++ b/activesupport/lib/active_support/ruby/shim.rb @@ -15,6 +15,7 @@ require 'active_support/core_ext/enumerable' require 'active_support/core_ext/process/daemon' require 'active_support/core_ext/string/conversions' require 'active_support/core_ext/string/interpolation' +require 'active_support/core_ext/string/encoding' require 'active_support/core_ext/rexml' require 'active_support/core_ext/time/conversions' require 'active_support/core_ext/file/path' diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb index 97b08da0e4..09ce39bae2 100644 --- a/activesupport/test/core_ext/string_ext_test.rb +++ b/activesupport/test/core_ext/string_ext_test.rb @@ -439,6 +439,14 @@ class OutputSafetyTest < ActiveSupport::TestCase test 'emits normal string yaml' do assert_equal 'foo'.to_yaml, 'foo'.html_safe.to_yaml(:foo => 1) end + + test 'knows whether it is encoding aware' do + if RUBY_VERSION >= "1.9" + assert 'ruby'.encoding_aware? + else + assert !'ruby'.encoding_aware? + end + end end class StringExcludeTest < ActiveSupport::TestCase |