summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--ext/json/lib/json/common.rb12
-rw-r--r--test/json/test_json_encoding.rb15
3 files changed, 22 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index ae0bdc81690..2a44dfd936f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Thu Dec 2 01:24:39 2010 NARUSE, Yui <naruse@ruby-lang.org>
+
+ * ext/json/lib/json/common.rb: don't use iconv on 1.9.
+ patched by Shota Fukumori [ruby-core:33164]
+
Thu Dec 2 01:02:03 2010 NARUSE, Yui <naruse@ruby-lang.org>
* ext/json: Update github/flori/json from 1.4.2+ to
diff --git a/ext/json/lib/json/common.rb b/ext/json/lib/json/common.rb
index d5444b92c82..13debd1366c 100644
--- a/ext/json/lib/json/common.rb
+++ b/ext/json/lib/json/common.rb
@@ -1,5 +1,4 @@
require 'json/version'
-require 'iconv'
module JSON
class << self
@@ -342,8 +341,15 @@ module JSON
end
# Shortuct for iconv.
- def self.iconv(to, from, string)
- Iconv.iconv(to, from, string).first
+ if String.method_defined?(:encode)
+ def self.iconv(to, from, string)
+ string.encode(to, from)
+ end
+ else
+ require 'iconv'
+ def self.iconv(to, from, string)
+ Iconv.iconv(to, from, string).first
+ end
end
end
diff --git a/test/json/test_json_encoding.rb b/test/json/test_json_encoding.rb
index fdea3296054..cdeca580922 100644
--- a/test/json/test_json_encoding.rb
+++ b/test/json/test_json_encoding.rb
@@ -7,7 +7,6 @@ when 'pure' then require 'json/pure'
when 'ext' then require 'json/ext'
else require 'json'
end
-require 'iconv'
class TC_JSONEncoding < Test::Unit::TestCase
include JSON
@@ -15,19 +14,21 @@ class TC_JSONEncoding < Test::Unit::TestCase
def setup
@utf_8 = '["© ≠ €!"]'
@parsed = [ "© ≠ €!" ]
- @utf_16_data = Iconv.iconv('utf-16be', 'utf-8', @parsed.first)
@generated = '["\u00a9 \u2260 \u20ac!"]'
- if defined?(::Encoding)
+ if String.method_defined?(:encode)
+ @utf_16_data = [@parsed.first.encode('utf-16be', 'utf-8')]
@utf_8_ascii_8bit = @utf_8.dup.force_encoding(Encoding::ASCII_8BIT)
- @utf_16be, = Iconv.iconv('utf-16be', 'utf-8', @utf_8)
+ @utf_16be = @utf_8.encode('utf-16be', 'utf-8')
@utf_16be_ascii_8bit = @utf_16be.dup.force_encoding(Encoding::ASCII_8BIT)
- @utf_16le, = Iconv.iconv('utf-16le', 'utf-8', @utf_8)
+ @utf_16le = @utf_8.encode('utf-16le', 'utf-8')
@utf_16le_ascii_8bit = @utf_16le.dup.force_encoding(Encoding::ASCII_8BIT)
- @utf_32be, = Iconv.iconv('utf-32be', 'utf-8', @utf_8)
+ @utf_32be = @utf_8.encode('utf-32be', 'utf-8')
@utf_32be_ascii_8bit = @utf_32be.dup.force_encoding(Encoding::ASCII_8BIT)
- @utf_32le, = Iconv.iconv('utf-32le', 'utf-8', @utf_8)
+ @utf_32le = @utf_8.encode('utf-32le', 'utf-8')
@utf_32le_ascii_8bit = @utf_32le.dup.force_encoding(Encoding::ASCII_8BIT)
else
+ require 'iconv'
+ @utf_16_data = Iconv.iconv('utf-16be', 'utf-8', @parsed.first)
@utf_8_ascii_8bit = @utf_8.dup
@utf_16be, = Iconv.iconv('utf-16be', 'utf-8', @utf_8)
@utf_16be_ascii_8bit = @utf_16be.dup