1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

json_escape makes json invalid doc change [#1485 state:resolved]

This commit is contained in:
Neeraj Singh 2010-04-27 21:55:24 -04:00 committed by Andrea Campi
parent 964033f351
commit a38e653a6d

View file

@ -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)