Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/spring/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
module Spring
module JSON
def self.load(string)
string = string.dup.force_encoding("utf-8") unless string.encoding == Encoding::UTF_8
OkJson.decode(string)
end

Expand Down
7 changes: 6 additions & 1 deletion test/unit/json_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ class JsonTest < ActiveSupport::TestCase
assert_equal({"unicode_example"=>"©"}, Spring::JSON.load('{"unicode_example": "\u00A9"}'))
end

test 'can decode binary strings with valid UTF8 characters' do
string = "{\"PS1\":\"\xEF\x90\x98 main \xEE\x9E\x91 v3.4.2\"}".b
assert_equal({"PS1"=>" main  v3.4.2"}, Spring::JSON.load(string))
end

test 'can encode' do
assert_equal('{}', Spring::JSON.dump({}))
end
end
end