aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorNeeraj Singh <neerajdotname@gmail.com>2010-04-27 21:55:24 -0400
committerAndrea Campi <andrea.campi@zephirworks.com>2010-10-16 21:57:19 +0200
commita38e653a6d512de3d22137cebc239d51f2513502 (patch)
treea8945a7d5b5aea3d44c9b16b827826ec13e602e2 /activesupport
parent964033f35124bf9fc9bba0b4cd5c5cd176882902 (diff)
downloadrails-a38e653a6d512de3d22137cebc239d51f2513502.tar.gz
rails-a38e653a6d512de3d22137cebc239d51f2513502.tar.bz2
rails-a38e653a6d512de3d22137cebc239d51f2513502.zip
json_escape makes json invalid doc change [#1485 state:resolved]
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/core_ext/string/output_safety.rb6
1 files changed, 6 insertions, 0 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 b53929c2a3..e6f13ec12a 100644
--- a/activesupport/lib/active_support/core_ext/string/output_safety.rb
+++ b/activesupport/lib/active_support/core_ext/string/output_safety.rb
@@ -35,10 +35,16 @@ class ERB
# A utility method for escaping HTML entities in JSON strings.
# This method is also aliased as <tt>j</tt>.
#
+ # Note that after this operation is performed the output is not
+ # a valid JSON.
+ #
# In your ERb templates, use this method to escape any HTML entities:
# <%=j @person.to_json %>
#
# ==== Example:
+ # puts json_escape("{\"name\":\"john\",\"created_at\":\"2010-04-28T01:39:31Z\",\"id\":1}")
+ # # => {name:john,created_at:2010-04-28T01:39:31Z,id:1}
+ #
# puts json_escape("is a > 0 & a < 10?")
# # => is a \u003E 0 \u0026 a \u003C 10?
def json_escape(s)