Changeset 7747
- Timestamp:
- 10/05/07 10:07:23 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1-2-stable/activesupport/lib/active_support/json/encoders/core.rb
r5498 r7747 24 24 "\r" => '\r', 25 25 "\t" => '\t', 26 '"' => '\"', 27 '\\' => '\\\\' 26 '"' => '\"', 27 '\\' => '\\\\', 28 '<' => '\\074', 29 '>' => '\\076' 28 30 } 29 31 30 32 define_encoder String do |string| 31 '"' + string.gsub(/[\010\f\n\r\t"\\ ]/) { |s|33 '"' + string.gsub(/[\010\f\n\r\t"\\<>]/) { |s| 32 34 ESCAPED_CHARS[s] 33 35 }.gsub(/([\xC0-\xDF][\x80-\xBF]| branches/1-2-stable/activesupport/test/json_test.rb
r5498 r7747 1 1 require File.dirname(__FILE__) + '/abstract_unit' 2 2 3 class Foo3 class JsonFoo 4 4 def initialize(a, b) 5 5 @a, @b = a, b … … 15 15 16 16 StringTests = [[ 'this is the string', %("this is the string") ], 17 [ 'a "string" with quotes ', %("a \\"string\\" with quotes") ]]17 [ 'a "string" with quotes<script>', %("a \\"string\\" with quotes\\074script\\076") ]] 18 18 19 19 ArrayTests = [[ ['a', 'b', 'c'], %([\"a\", \"b\", \"c\"]) ], … … 24 24 [ :"a b", %("a b") ]] 25 25 26 ObjectTests = [[ Foo.new(1, 2), %({\"a\": 1, \"b\": 2}) ]]26 ObjectTests = [[ JsonFoo.new(1, 2), %({\"a\": 1, \"b\": 2}) ]] 27 27 28 28 VariableTests = [[ ActiveSupport::JSON::Variable.new('foo'), 'foo'], … … 72 72 def test_unquote_hash_key_identifiers 73 73 values = {0 => 0, 1 => 1, :_ => :_, "$" => "$", "a" => "a", :A => :A, :A0 => :A0, "A0B" => "A0B"} 74 assert_equal %({"a": "a", 0: 0, "_": "_", 1: 1, "$": "$", "A": "A", "A0B": "A0B", "A0": "A0"}), values.to_json 75 unquote(true) { assert_equal %({a: "a", 0: 0, _: "_", 1: 1, $: "$", A: "A", A0B: "A0B", A0: "A0"}), values.to_json } 74 75 assert_equal %({"a": "a"}), {"a"=>"a"}.to_json 76 assert_equal %({0: 0}), { 0 => 0 }.to_json 77 assert_equal %({"_": "_"}), {:_ =>:_ }.to_json 78 assert_equal %({"$": "$"}), {"$"=>"$"}.to_json 79 80 unquote(true) do 81 assert_equal %({a: "a"}), {"a"=>"a"}.to_json 82 assert_equal %({0: 0}), { 0 => 0 }.to_json 83 assert_equal %({_: "_"}), {:_ =>:_ }.to_json 84 assert_equal %({$: "$"}), {"$"=>"$"}.to_json 85 end 76 86 end 77 87