提交 42a06d2d 编写于 作者: J Jeremy Kemper

stdlib autoloads were hanging on 1.9.1

上级 ca492994
unless '1.9'.respond_to?(:each_char) unless '1.9'.respond_to?(:each_char)
autoload :StringScanner, 'strscan' unless defined? :StringScanner
class String class String
# Yields a single-character string for each character in the string. # Yields a single-character string for each character in the string.
# When $KCODE = 'UTF8', multi-byte characters are yielded appropriately. # When $KCODE = 'UTF8', multi-byte characters are yielded appropriately.
def each_char def each_char
scanner, char = StringScanner.new(self), /./mu require 'strscan' unless defined? ::StringScanner
scanner, char = ::StringScanner.new(self), /./mu
while c = scanner.scan(char) while c = scanner.scan(char)
yield c yield c
end end
......
autoload :YAML, 'yaml' unless defined? YAML
autoload :StringScanner, 'strscan' unless defined? StringScanner
require 'active_support/core_ext/string/starts_ends_with' require 'active_support/core_ext/string/starts_ends_with'
module ActiveSupport module ActiveSupport
...@@ -22,7 +19,8 @@ def decode(json) ...@@ -22,7 +19,8 @@ def decode(json)
# Ensure that ":" and "," are always followed by a space # Ensure that ":" and "," are always followed by a space
def convert_json_to_yaml(json) #:nodoc: def convert_json_to_yaml(json) #:nodoc:
scanner, quoting, marks, pos, times = StringScanner.new(json), false, [], nil, [] require 'strscan' unless defined? ::StringScanner
scanner, quoting, marks, pos, times = ::StringScanner.new(json), false, [], nil, []
while scanner.scan_until(/(\\['"]|['":,\\]|\\.)/) while scanner.scan_until(/(\\['"]|['":,\\]|\\.)/)
case char = scanner[1] case char = scanner[1]
when '"', "'" when '"', "'"
......
# encoding: UTF-8 # encoding: UTF-8
require 'abstract_unit' require 'abstract_unit'
class TestJSONDecoding < Test::Unit::TestCase class TestJSONDecoding < ActiveSupport::TestCase
TESTS = { TESTS = {
%q({"returnTo":{"\/categories":"\/"}}) => {"returnTo" => {"/categories" => "/"}}, %q({"returnTo":{"\/categories":"\/"}}) => {"returnTo" => {"/categories" => "/"}},
%q({returnTo:{"\/categories":"\/"}}) => {"returnTo" => {"/categories" => "/"}}, %q({returnTo:{"\/categories":"\/"}}) => {"returnTo" => {"/categories" => "/"}},
...@@ -36,7 +36,7 @@ class TestJSONDecoding < Test::Unit::TestCase ...@@ -36,7 +36,7 @@ class TestJSONDecoding < Test::Unit::TestCase
} }
TESTS.each do |json, expected| TESTS.each do |json, expected|
define_method :"test_json_decoding_#{json}" do test "json decodes #{json}" do
assert_nothing_raised do assert_nothing_raised do
assert_equal expected, ActiveSupport::JSON.decode(json) assert_equal expected, ActiveSupport::JSON.decode(json)
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册