Skip to content

Commit 6af2bf8

Browse files
committed
Let the adapter handle invalid UTF8
1 parent a8cff19 commit 6af2bf8

3 files changed

Lines changed: 5 additions & 1 deletion

File tree

lib/multi_json/adapter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ def cache(method, options)
4848

4949
def blank?(input)
5050
input.nil? || /\A\s*\z/ === input
51+
rescue ArgumentError # invalid byte sequence in UTF-8
52+
false
5153
end
5254

5355
end

lib/multi_json/adapters/ok_json.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ def load(string, options={})
1212
string = string.read if string.respond_to?(:read)
1313
result = ::MultiJson::OkJson.decode("[#{string}]").first
1414
options[:symbolize_keys] ? symbolize_keys(result) : result
15+
rescue ArgumentError # invalid byte sequence in UTF-8
16+
raise ParseError
1517
end
1618

1719
def dump(object, options={})

spec/shared/adapter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def to_json(*)
166166
end
167167

168168
it 'raises MultiJson::LoadError on blank input or invalid input' do
169-
[nil, '{"abc"}', ' ', "\t\t\t", "\n"].each do |input|
169+
[nil, '{"abc"}', ' ', "\t\t\t", "\n", "\x82\xAC\xEF"].each do |input|
170170
expect{MultiJson.load(input)}.to raise_error(MultiJson::LoadError)
171171
end
172172
end

0 commit comments

Comments
 (0)