Skip to content

Commit b545688

Browse files
committed
Fixed to do force_encoding when decoding JSON.
1 parent e5fc6b2 commit b545688

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

lib/spring/json.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
module Spring
1414
module JSON
1515
def self.load(string)
16-
OkJson.decode(string)
16+
OkJson.decode(string.dup.force_encoding("utf-8"))
1717
end
1818

1919
def self.dump(data)

test/unit/json_test.rb

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,11 @@ class JsonTest < ActiveSupport::TestCase
88

99
test 'can encode' do
1010
assert_equal('{}', Spring::JSON.dump({}))
11-
end
11+
end
12+
13+
test 'can encode and decode unicode characters' do
14+
encoded = Spring::JSON.dump({"unicode_example"=>"©".b})
15+
assert_equal('{"unicode_example":"©"}'.b, encoded)
16+
assert_equal({"unicode_example"=>"©"}, Spring::JSON.load(encoded))
17+
end
1218
end

0 commit comments

Comments
 (0)