Changeset 8026
- Timestamp:
- 10/26/07 03:22:02 (11 months ago)
- Files:
-
- trunk/activesupport/CHANGELOG (modified) (1 diff)
- trunk/activesupport/lib/active_support/json/decoding.rb (modified) (2 diffs)
- trunk/activesupport/lib/active_support/json/encoders/string.rb (modified) (2 diffs)
- trunk/activesupport/test/json/decoding_test.rb (modified) (2 diffs)
- trunk/activesupport/test/json/encoding_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activesupport/CHANGELOG
r8022 r8026 1 1 *SVN* 2 3 * Fix JSON encoding/decoding bugs dealing with /'s. Closes #9990 [Rick, theamazingrando] 2 4 3 5 * Introduce a base class for all test cases used by rails applications. ActiveSupport::TestCase [Koz] trunk/activesupport/lib/active_support/json/decoding.rb
r7865 r8026 44 44 45 45 if marks.empty? 46 json 46 json.gsub(/\\\//, '/') 47 47 else 48 48 # FIXME: multiple slow enumerations … … 52 52 join(" ") 53 53 times.each { |i| output[i-1] = ' ' } 54 output.gsub!(/\\\//, '/') 54 55 output 55 56 end trunk/activesupport/lib/active_support/json/encoders/string.rb
r7736 r8026 4 4 ESCAPED_CHARS = { 5 5 "\010" => '\b', 6 "\f" => '\f', 7 "\n" => '\n', 8 "\r" => '\r', 9 "\t" => '\t', 10 '"' => '\"', 11 '\\' => '\\\\', 12 ">" => '\076', 13 '<' => '\074' 6 "\f" => '\f', 7 "\n" => '\n', 8 "\r" => '\r', 9 "\t" => '\t', 10 '"' => '\"', 11 '\\' => '\\\\', 12 ">" => '\076', 13 '<' => '\074', 14 '/' => '\\/' 14 15 } 15 16 end … … 19 20 class String 20 21 def to_json(options = nil) #:nodoc: 21 '"' + gsub(/[\010\f\n\r\t"\\>< ]/) { |s|22 '"' + gsub(/[\010\f\n\r\t"\\><\/]/) { |s| 22 23 ActiveSupport::JSON::Encoding::ESCAPED_CHARS[s] 23 24 }.gsub(/([\xC0-\xDF][\x80-\xBF]| trunk/activesupport/test/json/decoding_test.rb
r7613 r8026 3 3 class TestJSONDecoding < Test::Unit::TestCase 4 4 TESTS = { 5 % ({"returnTo":{"/categories":"/"}}) => {"returnTo" => {"/categories" => "/"}},6 % ({returnTo:{"/categories":"/"}}) => {"returnTo" => {"/categories" => "/"}},7 % ({"return\\"To\\":":{"/categories":"/"}}) => {"return\"To\":" => {"/categories" => "/"}},8 % ({"returnTo":{"/categories":1}}) => {"returnTo" => {"/categories" => 1}},5 %q({"returnTo":{"\/categories":"\/"}}) => {"returnTo" => {"/categories" => "/"}}, 6 %q({returnTo:{"\/categories":"\/"}}) => {"returnTo" => {"/categories" => "/"}}, 7 %q({"return\\"To\\":":{"\/categories":"\/"}}) => {"return\"To\":" => {"/categories" => "/"}}, 8 %q({"returnTo":{"\/categories":1}}) => {"returnTo" => {"/categories" => 1}}, 9 9 %({"returnTo":[1,"a"]}) => {"returnTo" => [1, "a"]}, 10 10 %({"returnTo":[1,"\\"a\\",", "b"]}) => {"returnTo" => [1, "\"a\",", "b"]}, … … 24 24 %(null) => nil, 25 25 %(true) => true, 26 %(false) => false 26 %(false) => false, 27 %q("http:\/\/test.host\/posts\/1") => "http://test.host/posts/1" 27 28 } 28 29 29 def test_json_decoding30 TESTS.each do |json, expected|30 TESTS.each do |json, expected| 31 define_method :"test_json_decoding_#{json}" do 31 32 assert_nothing_raised do 32 33 assert_equal expected, ActiveSupport::JSON.decode(json) trunk/activesupport/test/json/encoding_test.rb
r8010 r8026 15 15 16 16 StringTests = [[ 'this is the <string>', %("this is the \\074string\\076")], 17 [ 'a "string" with quotes', %("a \\"string\\" with quotes") ]] 17 [ 'a "string" with quotes', %("a \\"string\\" with quotes") ], 18 [ 'http://test.host/posts/1', %("http:\\/\\/test.host\\/posts\\/1")]] 18 19 19 20 ArrayTests = [[ ['a', 'b', 'c'], %([\"a\", \"b\", \"c\"]) ],