Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

root/trunk/activesupport/lib/active_support/json.rb

Revision 9238, 1.7 kB (checked in by rick, 3 months ago)

Add config.active_support.escape_html_entities_in_json to allow disabling of html entity escaping. [rick]

Line 
1
2
3 module ActiveSupport
4   # If true, use ISO 8601 format for dates and times.  Otherwise, fall back to the ActiveSupport legacy format.
5   mattr_accessor :use_standard_json_time_format
6
7   class << self
8     def escape_html_entities_in_json
9       @escape_html_entities_in_json
10     end
11
12     def escape_html_entities_in_json=(value)
13       ActiveSupport::JSON::Encoding.escape_regex = \
14         if value
15           /[\010\f\n\r\t"\\><&]/
16         else
17           /[\010\f\n\r\t"\\]/
18         end
19       @escape_html_entities_in_json = value
20     end
21   end
22
23   module JSON
24     RESERVED_WORDS = %w(
25       abstract      delete        goto          private       transient
26       boolean       do            if            protected     try
27       break         double        implements    public        typeof
28       byte          else          import        return        var
29       case          enum          in            short         void
30       catch         export        instanceof    static        volatile
31       char          extends       int           super         while
32       class         final         interface     switch        with
33       const         finally       long          synchronized
34       continue      float         native        this
35       debugger      for           new           throw
36       default       function      package       throws
37     ) #:nodoc:
38
39     class << self
40       def valid_identifier?(key) #:nodoc:
41         key.to_s =~ /^[[:alpha:]_$][[:alnum:]_$]*$/ && !reserved_word?(key)
42       end
43
44       def reserved_word?(key) #:nodoc:
45         RESERVED_WORDS.include?(key.to_s)
46       end
47     end
48   end
49 end
50
51 require 'active_support/json/encoding'
52 require 'active_support/json/decoding'
Note: See TracBrowser for help on using the browser.