Permalink
Browse files

Enabling quirks_mode by default for json_gem/json_pure adapters

  • Loading branch information...
rwz committed Mar 8, 2013
1 parent 16c19b8 commit 1fd4e6635c436515b7d7d5a0bee4548de8571520
Showing with 7 additions and 6 deletions.
  1. +3 −2 lib/multi_json/adapters/json_common.rb
  2. +4 −4 spec/json_common_shared_example.rb
@@ -3,12 +3,13 @@
module MultiJson
module Adapters
class JsonCommon < Adapter
- defaults :load, :create_additions => false
+ defaults :load, :create_additions => false, :quirks_mode => true
def load(string, options={})
string = string.read if string.respond_to?(:read)
+ string.force_encoding(::Encoding::ASCII_8BIT) if string.respond_to?(:force_encoding)
options[:symbolize_names] = true if options.delete(:symbolize_keys)
- ::JSON.parse("[#{string}]", options).first
+ ::JSON.parse(string, options)
end
def dump(object, options={})
@@ -7,24 +7,24 @@
describe 'with :pretty option set to true' do
it 'passes default pretty options' do
object = 'foo'
- object.should_receive(:to_json).with(JSON::PRETTY_STATE_PROTOTYPE.to_h).and_return('["foo"]')
+ object.should_receive(:to_json).with(JSON::PRETTY_STATE_PROTOTYPE.to_h)
MultiJson.dump(object, :pretty => true)
end
end
describe 'with :indent option' do
it 'passes it on dump' do
object = 'foo'
- object.should_receive(:to_json).with(:indent => "\t").and_return('["foo"]')
+ object.should_receive(:to_json).with(:indent => "\t")
MultiJson.dump(object, :indent => "\t")
end
end
end
describe '.load' do
it 'passes :quirks_mode option' do
- ::JSON.should_receive(:parse).with('["foo"]', {:quirks_mode => true, :create_additions => false}).and_return(['foo'])
- MultiJson.load('"foo"', :quirks_mode => true)
+ ::JSON.should_receive(:parse).with('[123]', {:quirks_mode => false, :create_additions => false})
+ MultiJson.load('[123]', :quirks_mode => false)
end
end
end

0 comments on commit 1fd4e66

Please sign in to comment.