diff options
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/CHANGELOG.md | 6 | ||||
-rw-r--r-- | activesupport/lib/active_support/json/encoding.rb | 1 | ||||
-rw-r--r-- | activesupport/lib/active_support/json/variable.rb | 17 | ||||
-rw-r--r-- | activesupport/test/json/encoding_test.rb | 7 |
4 files changed, 26 insertions, 5 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index 70bd1bf4d3..6229b89a91 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,10 +1,6 @@ ## Rails 4.0.0 (unreleased) ## -* Add String#indent. *fxn & Ace Suares* - -* Inflections can now be defined per locale. `singularize` and `pluralize` accept locale as an extra argument. *David Celis* - -* `Object#try` will now return nil instead of raise a NoMethodError if the receiving object does not implement the method, but you can still get the old behavior by using the new `Object#try!` *DHH* +* `ERB::Util.html_escape` now escapes single quotes. *Santiago Pastorino* * `Time#change` now works with time values with offsets other than UTC or the local time zone. *Andrew White* diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb index 389df58ec4..1a95bd63e6 100644 --- a/activesupport/lib/active_support/json/encoding.rb +++ b/activesupport/lib/active_support/json/encoding.rb @@ -1,5 +1,6 @@ require 'active_support/core_ext/object/to_json' require 'active_support/core_ext/module/delegation' +require 'active_support/json/variable' require 'bigdecimal' require 'active_support/core_ext/big_decimal/conversions' # for #to_s diff --git a/activesupport/lib/active_support/json/variable.rb b/activesupport/lib/active_support/json/variable.rb new file mode 100644 index 0000000000..8af661a795 --- /dev/null +++ b/activesupport/lib/active_support/json/variable.rb @@ -0,0 +1,17 @@ +require 'active_support/deprecation' + +module ActiveSupport + module JSON + # Deprecated: A string that returns itself as its JSON-encoded form. + class Variable < String + def initialize(*args) + ActiveSupport::Deprecation.warn 'ActiveSupport::JSON::Variable is deprecated and will be removed in Rails 4.1. ' \ + 'For your own custom JSON literals, define #as_json and #encode_json yourself.' + super + end + + def as_json(options = nil) self end #:nodoc: + def encode_json(encoder) self end #:nodoc: + end + end +end diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb index a947635f4a..7ed71f9abc 100644 --- a/activesupport/test/json/encoding_test.rb +++ b/activesupport/test/json/encoding_test.rb @@ -85,6 +85,13 @@ class TestJSONEncoding < ActiveSupport::TestCase end end + def test_json_variable + assert_deprecated do + assert_equal ActiveSupport::JSON::Variable.new('foo'), 'foo' + assert_equal ActiveSupport::JSON::Variable.new('alert("foo")'), 'alert("foo")' + end + end + def test_hash_encoding assert_equal %({\"a\":\"b\"}), ActiveSupport::JSON.encode(:a => :b) assert_equal %({\"a\":1}), ActiveSupport::JSON.encode('a' => 1) |