Skip to content

Commit

Permalink
Ensure json tests run in stable.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/1-2-stable@7747 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
NZKoz committed Oct 5, 2007
1 parent ebe8bc3 commit 4c458f8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
8 changes: 5 additions & 3 deletions activesupport/lib/active_support/json/encoders/core.rb
Expand Up @@ -23,12 +23,14 @@ module Encoders #:nodoc:
"\n" => '\n',
"\r" => '\r',
"\t" => '\t',
'"' => '\"',
'\\' => '\\\\'
'"' => '\"',
'\\' => '\\\\',
'<' => '\\074',
'>' => '\\076'
}

define_encoder String do |string|
'"' + string.gsub(/[\010\f\n\r\t"\\]/) { |s|
'"' + string.gsub(/[\010\f\n\r\t"\\<>]/) { |s|
ESCAPED_CHARS[s]
}.gsub(/([\xC0-\xDF][\x80-\xBF]|
[\xE0-\xEF][\x80-\xBF]{2}|
Expand Down
20 changes: 15 additions & 5 deletions activesupport/test/json.rb → activesupport/test/json_test.rb
@@ -1,6 +1,6 @@
require File.dirname(__FILE__) + '/abstract_unit'

class Foo
class JsonFoo
def initialize(a, b)
@a, @b = a, b
end
Expand All @@ -14,7 +14,7 @@ class TestJSONEmitters < Test::Unit::TestCase
[ 2.5, %(2.5) ]]

StringTests = [[ 'this is the string', %("this is the string") ],
[ 'a "string" with quotes', %("a \\"string\\" with quotes") ]]
[ 'a "string" with quotes<script>', %("a \\"string\\" with quotes\\074script\\076") ]]

ArrayTests = [[ ['a', 'b', 'c'], %([\"a\", \"b\", \"c\"]) ],
[ [1, 'a', :b, nil, false], %([1, \"a\", \"b\", null, false]) ]]
Expand All @@ -23,7 +23,7 @@ class TestJSONEmitters < Test::Unit::TestCase
[ :this, %("this") ],
[ :"a b", %("a b") ]]

ObjectTests = [[ Foo.new(1, 2), %({\"a\": 1, \"b\": 2}) ]]
ObjectTests = [[ JsonFoo.new(1, 2), %({\"a\": 1, \"b\": 2}) ]]

VariableTests = [[ ActiveSupport::JSON::Variable.new('foo'), 'foo'],
[ ActiveSupport::JSON::Variable.new('alert("foo")'), 'alert("foo")']]
Expand Down Expand Up @@ -71,8 +71,18 @@ def test_exception_raised_when_encoding_circular_reference

def test_unquote_hash_key_identifiers
values = {0 => 0, 1 => 1, :_ => :_, "$" => "$", "a" => "a", :A => :A, :A0 => :A0, "A0B" => "A0B"}
assert_equal %({"a": "a", 0: 0, "_": "_", 1: 1, "$": "$", "A": "A", "A0B": "A0B", "A0": "A0"}), values.to_json
unquote(true) { assert_equal %({a: "a", 0: 0, _: "_", 1: 1, $: "$", A: "A", A0B: "A0B", A0: "A0"}), values.to_json }

assert_equal %({"a": "a"}), {"a"=>"a"}.to_json
assert_equal %({0: 0}), { 0 => 0 }.to_json
assert_equal %({"_": "_"}), {:_ =>:_ }.to_json
assert_equal %({"$": "$"}), {"$"=>"$"}.to_json

unquote(true) do
assert_equal %({a: "a"}), {"a"=>"a"}.to_json
assert_equal %({0: 0}), { 0 => 0 }.to_json
assert_equal %({_: "_"}), {:_ =>:_ }.to_json
assert_equal %({$: "$"}), {"$"=>"$"}.to_json
end
end

protected
Expand Down

0 comments on commit 4c458f8

Please sign in to comment.